资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

ios开发代码,iOS开发代码修改info文件不生效

ios 开发怎么用代码生成xml文件

在ios开发中,可以使用GDataXML生成xml

创新互联建站的客户来自各行各业,为了共同目标,我们在工作上密切配合,从创业型小企业到企事业单位,感谢他们对我们的要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。专业领域包括成都做网站、网站建设、电商网站开发、微信营销、系统平台开发。

GDataXML只有两个文件GDataXMLNode.h和GDataXMLNode.m。使用方法如下:

将文件包含进工程后,添加libxml2.dylib:

之后添加路径${SDK_ROOT}/usr/include/libxml2:

现在可以编写代码了:

#import "GDataXMLNode.h"

// 创建一个根标签

GDataXMLElement *rootElement = [GDataXMLNode elementWithName:@"root"];

// 创建一个属性

GDataXMLElement *attribute = [GDataXMLNode attributeWithName:@"a" stringValue:@"b"];

// 创建一个标签元素

GDataXMLElement *element = [GDataXMLNode elementWithName:@"user" stringValue:@"HelloWorld"];

// 把标签与属性添加到根标签中

[rootElement addAttribute:attribute];

[rootElement addChild:element];

// 生成xml文件内容

GDataXMLDocument *xmlDoc = [[GDataXMLDocument alloc] initWithRootElement:rootElement];

NSData *data1 = [xmlDoc XMLData];

NSString *xmlString = [[NSString alloc] initWithData:data1 encoding:NSWindowsCP1253StringEncoding];

NSLog(@"xmlString  %@", xmlString);

结果:

?xml version="1.0"?

root a="b"userHelloWorld/user/root

IOS开发以及Tab Bar使用讲解

为了更好理解使用用tabbar和切换视图,我们创建一个Empty Application。

   1、 打开Xcode ,新建项目

   2、 创建View Controller

在项目上按花键+N创建新文件,创建 Objective-C class 文件,按Next按钮,subClass 选UIViewController 。勾选上xib选项

以同样方式创建另外三个ViewController ,RedViewController ,GreyViewController,YellowViewController。四个View准备好了。那么Tabbar呢?

   3、 创建TabBarController.xib文件,选择创建Empty文件

这时候你发现创建的xib文件是空白的,不用慌,去右下角控件栏中把TabBar Controller拖过来就Ok了。

4、 关联TabBarController.xib ,tabbarAppDelegate这两个文件

在上图中选择File’s Owner,打开Identity Inspector,在Class一栏选择tabbarAppDelegate

这样,我们就可以创建TabBarController.xib 文件指向tabbarAppDelegate 文件的Outlet映射了。

5、 在Xcode中的工具栏的View菜单找到 打开Assistant Editor,使tabbarAppDelegate.h和TabBarController.xib 同时打开。

在xib文件上按住control键,往tabbarAppDelegate.h,创建Outlet.

弹出窗口输入 rootController,点connect。

   6、 添加代码

打开tabbarAppDelegate.m,在didFinishLaunchingWithOptions方法中添加代码:

1.- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

3. // Override point for customization after application launch.

4. [[NSBundle mainBundle] loadNibNamed:@"TabBarController" owner:self options:nil];

5. [self.window addSubview:self.rootController.view];

6. self.window.backgroundColor = [UIColor whiteColor];

7. [self.window makeKeyAndVisible];

8. return YES;

   7、 往TabBarController.xib上添加Tab Bar Item,

把控件栏上的Tab Bar Item控件往TabBarController.xib上拖拽即可,一个放4个。

   8 、关联Tab Bar Item和***ViewController。

选择其中一个Tab Bar Item,在右上角打开Identity Inspector,在Class中选择BlueViewController:

然后,打开Attribute,在NIB Name选择BlueViewController:

其他3个tab item重复类似的操作,选中对应的ViewController,这样在切换Tab标签时,就可以切换到对应的页面。

9、 设置tab item的属性

选中其中一个tab item ,会在右上角的属性栏里看到如下信息

Badge是红色圈圈里面有数字 ,表示有多少条信息的属性

Identifier 是tab item的样式,选custom是自定义,下面的是系统的样式。我选了其中四种。

bar ITem 的title image在custom的样式下能设置。

10 、剩下的3个Tab Item也做类似的设置即可。

现在基本完工,运行看看结果如何。好吧,其实和第一第二个图是一样的`,这里就不放了。

11 、在viewDidLoad方法加Log观察切换View

可以加写日志看看对应的View是什么时候运行的。第一个运行的View是BlueViewController,点击其他的tab项时,加载其他的view,加载一次之后下次点击不再调用viewDidLoad。

1.- (void)viewDidLoad

2. [super viewDidLoad];

3. NSLog(@"BlueViewController");

4. // Do any additional setup after loading the view from its nib.

iOS常用代码

//图片透明

- (UIImage *)imageWithColor:(UIColor *)color {

CGRect rect = CGRectMake(0.0f,0.0f, 1.0f,1.0f);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context =UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *image =UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

用: friendbg.image = [self imageWithColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]];;

在AppDelegate.m的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法里写

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

MainViewController *main = [[MainViewController alloc]init];

UINavigationController*nav = [[UINavigationController alloc]initWithRootViewController:main];

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

//创建并初始化UITabBarController

self.window.rootViewController = nav;

nav.navigationBarHidden = YES;

[self.window makeKeyAndVisible];

cell.h 中+(instancetype)xibTableViewCell;

cell.m 中+(instancetype)xibTableViewCell {

//在类方法中加载xib文件,注意:loadNibNamed:owner:options:这个方法返回的是NSArray,所以在后面加上firstObject或者lastObject或者[0]都可以;因为我们的Xib文件中,只有一个cell

return [[[NSBundle mainBundle] loadNibNamed:@"treasureCell" owner:nil options:nil] lastObject];

}

控制器.m中- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法中

static NSString *cellIndentifier = @"treasureCell";//这里的cellID就是cell的xib对应的名称

treasureCell *cell = (treasureCell *)[tableView dequeueReusableCellWithIdentifier:cellIndentifier];

if(nil == cell) {

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIndentifier owner:self options:nil];

    cell = [nib objectAtIndex:0]; //中间宽线

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

return cell;

// 手机版本控制

#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGTH))

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define IS_IPHONE_5 (IS_IPHONE SCREEN_MAX_LENGTH == 568.0)

#define IS_IPHONE_6 (IS_IPHONE SCREEN_MAX_LENGTH == 667.0)

#define IS_IPHONE_6p (IS_IPHONE SCREEN_MAX_LENGTH == 736.0)

#define ceshiURL @""//利好利空测试服务器

//判断是不是IPhoneX

#define isPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

// NSUserDefaults

#define UserSet(obj, key) [[NSUserDefaults standardUserDefaults] setObject:obj forKey:key]

#define UserObj(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]

#define UserSave [[NSUserDefaults standardUserDefaults] synchronize]

// 登录状态

#define IsLogin [[[NSUserDefaults standardUserDefaults] objectForKey:@"UseIsLogin"] isEqualToString:@"1"] ? 1 : 0

//获取屏幕宽高

#define KScreenWidth [[UIScreen mainScreen]bounds].size.width

#define KScreenHeight [[UIScreen mainScreen]bounds].size.height

#define kScreen_Bounds [UIScreen mainScreen].bounds

#define kScreenBg [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2];

//颜色

#define BGColor UICOLOR_HEX(0xfff8f8f8)//主背景颜色 (灰色)

#define MainColor UICOLOR_HEX(0xfffab615)//主颜色 (黄色)

#define TitleColor UICOLOR_HEX(0xff333333)//字颜色 (灰黑色)

#define MainWrightColor UICOLOR_HEX(0xffFFFFFF)//主白色颜色 (白色)

#define MainBlueColor UICOLOR_HEX(0xff08c9e6)//主蓝色颜色 (蓝色)

#define MainBlColor UICOLOR_HEX(0xff008fd1)//背景浅蓝色

#define MainTextColor UICOLOR_HEX(0xff00faeb)//文字淡蓝色

//获取16进制32位色的UIColor对象

#define UICOLOR_HEX(x) \

[UIColor \

colorWithRed:(float)((float)((x16)0xFF)/0xFF) \

green:(float)((float)((x8)0xFF)/0xFF) \

blue:(float)((float)(x0xFF)/(float)0xFF) \

alpha:(float)((float)((x24)0xFF)/(float)0xFF) \

]

////设置状态栏字体提

- (UIStatusBarStyle)preferredStatusBarStyle

{

return UIStatusBarStyleLightContent;//为白色

return UIStatusBarStyleDefault;//黑色

}


本文名称:ios开发代码,iOS开发代码修改info文件不生效
文章链接:http://cdkjz.cn/article/dsddiph.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220