iOS笔记16

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的懒加载造成的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值