-
解决同时按两个按钮进两个view的问题。
[button setExclusiveTouch:YES];
-
在6p模拟器上输出宽度是414,在6p真机上输出是375
是测试机本身设置的问题,到设置-显示与亮度里面把显示模式改成“标准” -
图片拉伸
UIImage* img=[UIImage imageNamed:@"2.png"];//原图UIEdgeInsets edge=UIEdgeInsetsMake(0, 10, 0,10);//UIImageResizingModeStretch:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片//UIImageResizingModeTile:平铺模式,通过重复显示UIEdgeInsets指定的矩形区域来填充图img= [img resizableImageWithCapInsets:edge resizingMode:UIImageResizingModeStretch];self.imageView.image=img;
-
UITableView顶部有空白区,cell不在最顶端问题
iOS 7 viewcontroller新增属性automaticallyAdjustsScrollViewInsets,即是否根据按所在界面的
navigationbar与tabbar的高度,自动调整scrollview的 inset,设置为no,让它不要自动调整就可以了self.automaticallyAdjustsScrollViewInsets=NO;
-
修改tableViewCell选中状态的颜色
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame]; cell.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
-
默认选中第一个cell
NSInteger selectedIndex = 0; NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0]; [_leftSiftTable selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
-
设置btn上的字左对齐
timeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; timeBtn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
-
修改textFieldplaceholder字体颜色和大小
textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
-
改变UILable字体大小,使内容自适应
方法一:lab.adjustsFontSizeToFitWidth = YES;
方法二:label.numberOfLines = 0; label.lineBreakMode = NSLineBreakByWordWrapping;
-
修改状态栏字体颜色
设置两种颜色,黑色和白色,系统默认黑色
设置为白色方法:
(1)在plist里面添加Status bar style,值为UIStatusBarStyleLightContent(白色)或UIStatusBarStyleDefault(黑 色)
(2)在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO利用run time可以对状态栏的view随意设
-
关于右划返回上一级
自定义leftBarButtonItem后无法启用系统自带的右划返回可以再设置以下代码self.navigationController.interactivePopGestureRecognizer.delegate = self;
-
去掉导航栏下边的黑线
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
-
点击cell单元格的时候取消选中单元格
-(void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; }
-
修改pagecontrol颜色
_pageControl.currentPageIndicatorTintColor=SFQRedColor; _pageControl.pageIndicatorTintColor=SFQGrayColor;
-
UIView和UIImageview的userInteractionEnabled属性
UIView的userInteractionEnabled默认是YES UIImageview的userInteractionEnabled默认是NO userInteractionEnabled=YES则代表该视图可交互,则不响应父视图。 userInteractionEnabled=NO不可交互,则该视图上的子视图也不会响应。
-
去掉UITableView的section的粘性,使其不会悬停。
//有时候使用UITableView所实现的列表,会使用到section,但是又不希望它粘在最顶上而是跟随滚动而消失或者出现- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == _tableView) {
CGFloat sectionHeaderHeight = 36; if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
}
17.去掉tabBar顶部线条
我们可以有两种的解决办法,如果你的tabbar高度是在49px而背景图没有超过这个高度的话可以使用
[self.tabBar setClipsToBounds:YES];
如果我们的高度是高于49的话,可以使用
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6)
{
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
}
18.UITableView每个cell之间的默认分割线怎么去掉
tableView.separatorStyle = NO;
19.取消UITableView每个cell选中变灰状态
[tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
20.可以达到让背景成为任何颜色的半透明而且其子控件不透明。
1》对UIColor自带的方法colorWithRed:green:blue:alpha:
2》
UIColor *color = [UIColor blackColor];
bgView.backgroundColor = [color colorWithAlphaComponent:0.5];
21.项目需求需要,在外部tableview偏移量达到设定值时,固定外部的tableview,手势处理需要由cell中的tableview来处理。
添加手势的话,在手势代理方法中判断当前作用页面,就可以区分是哪个tableview
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([NSStringFromClass(touch.view.class) isEqualToString:@"FirstTableView"]) {
//如果是FirstTableView的范围,那么手势不生效
return NO;
}
}
自身的代理点击方法也一样,判断tableview
22.根据具体情况来选择性的使用 xib 和 storyboard。这里有我的一些建议:
- 对于复杂的、动态生成的界面,建议使用手工编写界面。
- 对于需要统一风格的按钮或UI控件,建议使用手工用代码来构造。方便之后的修改和复用。
- 对于需要有继承或组合关系的 UIView 类或 UIViewController 类,建议用代码手工编写界面。
- 对于那些简单的、静态的、非核心功能界面,可以考虑使用 xib 或 storyboard 来完成。
23.
1.不要在loadView中调用父类方法[super loadView],因为这会影响CPU性能。
2.切换前后台不会调用viewWillAppear