图片来自网络
1.卡片式UITableViewCell的处理方式
-
代码(在自定义cell中重写 setFrame 方法即可)
- (void)setFrame:(CGRect)frame { static CGFloat margin = 10; // margin为离边界距离,可根据需要设定 frame.origin.x = margin; frame.origin.y += margin; frame.size.width -= 2 * margin; frame.size.height -= margin; [super setFrame:frame]; }
-
效果
未重写效果
重写后效果
2.UIButton之上面为图片,下面为标题的处理方式
-
代码(自定义UIButton,重写其 layoutSubviews 方法)
自定义UIButton .m 文件
#import "SJButton.h" @implementation SJButton - (void)layoutSubviews { [super layoutSubviews]; // 调整图片(图片为正方形) CGRect imageRect = self.imageView.frame; imageRect.origin.x = 0; imageRect.origin.y = 0; imageRect.size.width = self.bounds.size.width; imageRect.size.height = imageRect.size.width; self.imageView.frame = imageRect; // 调整文字(文字为长方形,宽度和图片一样,高度为整个Button高度减去图片高度) CGRect titleRect = self.titleLabel.frame; titleRect.origin.x = 0; titleRect.origin.y = self.imageView.bounds.size.height; titleRect.size.width = self.imageView.bounds.size.width; titleRect.size.height = self.bounds.size.height - titleRect.size.width; self.titleLabel.frame = titleRect; } @end
在控制器中的初始化代码
SJButton *btn = [SJButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(100, 100, 70, 90); btn.backgroundColor = [UIColor blackColor]; [btn setImage:[UIImage imageNamed:@"login_sina_icon_click"] forState:UIControlStateNormal]; [btn setTitle:@"微博登录" forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:15.0]; btn.titleLabel.textAlignment = NSTextAlignmentCenter; [self.view addSubview:btn];
-
效果
自定义Button
3.状态栏的相关设置
-
代码(在控制器中)
- (UIStatusBarStyle)preferredStatusBarStyle // 设置状态栏信息颜色 { return UIStatusBarStyleDefault; // 黑字 // return UIStatusBarStyleLightContent; // 白字 } - (BOOL)prefersStatusBarHidden // 设置状态栏的Hidden { return YES; }
4.程序的锁屏设置
-
说明:应用在一段时间内没有进行触屏操作时会进入锁屏模式,但在某些情况下不需要锁屏(如视频播放类),可以设置如下属性。
-
代码
[UIApplication sharedApplication].idleTimerDisabled = YES; 或[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
5.CocoaPods pod install/update更新慢的处理
pod install --verbose --no-repo-update pod update --verbose --no-repo-update 如果不加后面的参数,默认会升级CocoaPods的spec仓库,加一个参数可以省略这一步,然后速度就会提升不少
6.设置UITableView上accessoryType颜色
-
代码
self.tableView.tintColor = [UIColor redColor];
-
效果
accessoryType颜色效果
7.像safari一样滑动的时候隐藏navigationbar
-
代码
self.navigationController.hidesBarsOnSwipe = YES;
8.学会navigationItem的rightBarButtonItems属性
-
代码
self.navigationItem.rightBarButtonItems = @[ [UIBarButtonItem itemWithImage:@"mine-setting-icon" highlightImage:@"mine-setting-icon-click" targer:self action:@selector(settingClick)], [UIBarButtonItem itemWithImage:@"mine-moon-icon" highlightImage:@"mine-moon-icon-click" targer:self action:@selector(moonClick)] ];
-
效果
rightBarButtonItems 属性
来自:http://www.jianshu.com/p/b1bb62b5880a