您的位置:首页 > 其它

知识点总结 2

2015-06-10 14:13 323 查看
一、按钮的设置

0.设置背景图片

[btn setBackgroundImage:image forState:UIControlStateNormal];

1.设置内部UIImageView的图片

[btn setImage:image forState:UIControlStateNormal];

// 不能写成btn.imageView.image = image;

2.设置内部UILabel的文字

[btn setTitle:@"43" forState:UIControlStateNormal];

// 不能写成btn.titleLabel.text = @"43";

3.调整内部ImageView的frame

- (CGRect)imageRectForContentRect:(CGRect)contentRect

4.调整内部UILabel的frame

- (CGRect)titleRectForContentRect:(CGRect)contentRect

5.覆盖父类在highlighted时的所有操作

- (void)setHighlighted:(BOOL)highlighted { }

6.文字居中

self.titleLabel.textAlignment = NSTextAlignmentCenter;

7.文字大小

self.titleLabel.font = [UIFont systemFontOfSize:12];

8.图片的内容模式

self.imageView.contentMode = UIViewContentModeCenter;

二、添加子控制器

- (void)addChildViewController:

* 会将子控制器添加到childViewControllers,并且子控制器是有顺序的

* 目的就是持有子控制器,不让子控制器销毁,保证主控制器在,子控制器就在

三、让一个控制器拥有导航栏的最快方法:包装一层导航控制器

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

四、UIBarButtonItem

1> 创建一个带有文字的item

[[UIBarButtonItem alloc] initWithTitle:@"设置" style:UIBarButtonItemStyleBordered target:nil action:nil]

2> 创建一个包装了自定义View的item

- (id)initWithCustomView:(UIView *)customView

五、设置导航栏UINavigationBar主题

// 1.appearance方法返回一个导航栏的外观对象

// 修改了这个外观对象,相当于修改了整个项目中的外观

UINavigationBar *bar = [UINavigationBar appearance];

// 2.设置导航栏的背景图片

[bar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

// 3.设置导航栏文字的主题

[bar setTitleTextAttributes:@{

  UITextAttributeTextColor : [UIColor blackColor],

  UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]

 }];

六、设置导航按钮UIBarButtonItem主题

// 1.修改所有UIBarButtonItem的外观

UIBarButtonItem *barItem = [UIBarButtonItem appearance];

// 2.修改item的背景图片

[barItem setBackgroundImage:image1 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

[barItem setBackgroundImage:image2 forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

// 3.修改item上面的文字样式

NSDictionary *dict = @{

    UITextAttributeTextColor : [UIColor darkGrayColor],

    UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]

};

[barItem setTitleTextAttributes:dict forState:UIControlStateNormal];

[barItem setTitleTextAttributes:dict forState:UIControlStateHighlighted];

七、设置状态栏样式

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: