星空网 > 软件开发 > 操作系统

iOS开发常用小技巧记录(持续更新)

  • 以下问题都是自己在项目中遇到的,解决问题的方法肯定有多种,我所列举的不一定就是最好的解决办法。如有问题欢迎大家指正,补充,交流。

 

 

  1. 解决同时按两个按钮进两个view的问题。
    [button setExclusiveTouch:YES];

  2. 在6p模拟器上输出宽度是414,在6p真机上输出是375
    是测试机本身设置的问题,到设置-显示与亮度里面把显示模式改成“标准”

  3. 图片拉伸

    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;
  4. UITableView顶部有空白区,cell不在最顶端问题
    iOS 7 viewcontroller新增属性automaticallyAdjustsScrollViewInsets,即是否根据按所在界面的
    navigationbar与tabbar的高度,自动调整scrollview的 inset,设置为no,让它不要自动调整就可以了

    self.automaticallyAdjustsScrollViewInsets=NO;
  5. 修改tableViewCell选中状态的颜色

    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];cell.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
  6. 默认选中第一个cell

     NSInteger selectedIndex = 0; NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0]; [_leftSiftTable selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  7. 设置btn上的字左对齐

    timeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;timeBtn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
  8. 修改textFieldplaceholder字体颜色和大小

    textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
  9. 改变UILable字体大小,使内容自适应
    方法一:
    lab.adjustsFontSizeToFitWidth=YES;
    方法二:

    label.numberOfLines = 0;label.lineBreakMode = NSLineBreakByWordWrapping;
  10. 修改状态栏字体颜色
    只能设置两种颜色,黑色和白色,系统默认黑色
    设置为白色方法:
    (1)在plist里面添加Status bar style,值为UIStatusBarStyleLightContent(白色)或UIStatusBarStyleDefault(黑 色)
    (2)在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO

  11. 关于右划返回上一级
    自定义leftBarButtonItem后无法启用系统自带的右划返回可以再设置以下代码

    self.navigationController.interactivePopGestureRecognizer.delegate = self;
  12. 去掉导航栏下边的黑线

    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
  13. 点击cell单元格的时候取消选中单元格

    -(void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{[tableView deselectRowAtIndexPath:indexPath animated:YES];}
  14. 修改pagecontrol颜色

    _pageControl.currentPageIndicatorTintColor=SFQRedColor;_pageControl.pageIndicatorTintColor=SFQGrayColor;
  15. UIView和UIImageview的userInteractionEnabled属性
    UIView的userInteractionEnabled默认是YESUIImageview的userInteractionEnabled默认是NOuserInteractionEnabled=YES则代表该视图可交互,则不响应父视图。userInteractionEnabled=NO不可交互,则该视图上的子视图也不会响应。

  16. 去掉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);     }   } }



文/Simba_LX(简书作者)
原文链接:http://www.jianshu.com/p/970469cb0428
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。



原标题:iOS开发常用小技巧记录(持续更新)

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

开在境外开户:https://www.goluckyvip.com/tag/72660.html
免费国外网络账户开户多少钱:https://www.goluckyvip.com/tag/72668.html
海外抖音开户:https://www.goluckyvip.com/tag/72669.html
谷歌收购模式:https://www.goluckyvip.com/tag/7267.html
美原油国内开户:https://www.goluckyvip.com/tag/72671.html
为外国政要开立账户时:https://www.goluckyvip.com/tag/72672.html
小米SU7的不甘心全写进了 “周边”的商品链接里 :https://www.kjdsnews.com/a/1836549.html
10天涨粉300+万 “王婆说媒”凭什么一夜爆红? :https://www.kjdsnews.com/a/1836550.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流