您的位置:首页 > 移动开发 > IOS开发

iOS笔记16

2015-11-30 20:35 330 查看
1

//控制器视图原点和大小问题:translucent、edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets(ScrollView适用)

iOS7之后,控制器的视图默认是全屏大小但是以下情况:

1.子视图没有scrollView的情况下(导航控制器中)self.navigationBar.translucent = NO和(子控制器中)self.edgesForExtendedLayout = UIRectEdgeNone属性

都会使视图的原点由左上角变成导向栏下边,但是translucent的优先级比edgesForExtendedLayout高

(什么意思呢?当navigationBar.translucent为NO的时候,不管edgesForExtendedLayout怎么设置,控图的原点值都是从导航栏下方算起)

给navigationBar设置背景图片,效果类似navigationBar.translucent=NO

2.有ScrollView情况下:
控制器默认会调整ScrollView的contentInset,使它的contentInset.top值为64.但是automaticallyAdjustsScrollViewInsets为NO,会使top值变为0。
而设置navigationBar.translucent = NO 效果类似 与 edgesForExtendedLayout = UIRectEdgeNone。视图的坐标原点会从导航栏最下沿开始算起。

3.tabBar.translucent  = NO 或者给tabbar设置背景图片,会使视图的底部变成tabbar的上边沿,而不是屏幕的底部(通过debug模式查看)


2

//使用AutoLayout别忘了设置translatesAutoresizingMaskIntoConstraints

设置translatesAutoresizingMaskIntoConstraints = NO

3

//[UINavigationBar appearance]、[UIBarButtonItem appearance]、修改导航栏文字颜色、修改导航栏按钮的样式、tintColor

UINavigationBar *bar = [UINavigationBar appearance];

[bar setBackgroundImage:[UIImage imageNamed:@”navbar64”] forBarMetrics:UIBarMetricsDefault];

// 2.修改导航栏文字颜色
NSDictionary *dict = @{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont systemFontOfSize:18]
};

////----------------------------------------有点疑问
bar.tintColor = [UIColor whiteColor];

[bar setTitleTextAttributes:dict];

// 2.修改导航栏按钮的样式
UIBarButtonItem *item= [UIBarButtonItem appearance];
NSDictionary *dict1 = @{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont systemFontOfSize:14]
};
[item setTitleTextAttributes:dict1 forState:UIControlStateNormal];
[item setTitleTextAttributes:dict1 forState:UIControlStateHighlighted];


4

//调整导航栏按钮的间距 (UIBarButtonSystemItemFixedSpace)

// 创建间距按钮

UIBarButtonItem *space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

space.width = -12;

5

//NSMutableAttributedString

NSString *str = @”没有账号,马上注册>”;

// 创建一个富文本字符串

NSMutableAttributedString *attribiuteStr = [[NSMutableAttributedString alloc]initWithString:str];

// 给字符设置文本属性

[attribiuteStr addAttributes:@{

NSFontAttributeName : [UIFont systemFontOfSize:14],

NSForegroundColorAttributeName : [UIColor blackColor]

} range:NSMakeRange(0, str.length)];

NSRange range = [str rangeOfString:@”马上注册>”];

[attribiuteStr addAttributes:@{

NSFontAttributeName : [UIFont systemFontOfSize:14],

NSForegroundColorAttributeName : [UIColor blueColor]

} range:range];

[self.btnRegister setAttributedTitle:attribiuteStr forState:UIControlStateNormal];

6

//创建指向自己的弱指针

define __weakSelf __weak typeof(self) weakSelf = self;

// 可以用__unsafe_unretained替代

__weak XMGSettingController *weakSelf = self;

7

//下面的情况会发生内存泄漏 .需要配合6使用

pushAndRemind.action = ^{

FFPushNoteViewController *pushNoteVc = [[FFPushNoteViewController alloc] init];

[self.navigationController pushViewController:pushNoteVc animated:YES];

};

8

// 取消cell的点击背景色 可以通过取消点击的来做出效果

[tableView deselectRowAtIndexPath:indexPath animated:YES];

9

//若push一个控制器,控制器显示的时候出现卡顿的现象 有可能是控制器view的懒加载造成的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios