关于iOS 开发的几个小问题解决办法

iOS开发中经常会遇到一些小问题 例如 列表cell的分隔线俩端对齐 图片裁截 导航栏颜色与设置颜色不符合 label内容俩端对齐

列表cell的分隔线俩端对齐 这个方法是iOS9.0以后出现的 实用的时候需要做判断 否则回报错奔溃

viewdidload  方法里
//判断设备系统
NSString *version = [UIDevice currentDevice].systemVersion;
    if (version.doubleValue >= 9.0){
        if ([self.shishiTable respondsToSelector:@selector(setSeparatorInset:)]) {
            [self.shishiTable setSeparatorInset:UIEdgeInsetsZero];
        }
        if ([self.shishiTable respondsToSelector:@selector(setLayoutMargins:)]) {
            [self.shishiTable setLayoutMargins:UIEdgeInsetsZero];
       }
}
//cell  方法里继续调用
NSString *version = [UIDevice currentDevice].systemVersion;
    if (version.doubleValue >= 9.0){
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
            [cell setSeparatorInset:UIEdgeInsetsZero];
        }
        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
            [cell setLayoutMargins:UIEdgeInsetsZero];
        }
    }
//可以完美实现 cell分割线俩端对齐 iOS9.0以后手机 (这里做个记录 有什么其他方法希望大家来交流)

关于图片裁截

 imgview 裁截
imgView1.contentMode=UIViewContentModeScaleAspectFill;
图片比例不变 填充整个imageview 有一部分显示不出来
imgView1.clipsToBounds=YES;
裁截显示不出来的部分

导航栏颜色与设置颜色不同

//设置导航栏颜色
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:248/256.0 green:62/256.0 blue:59/256.0 alpha:1];
//去除导航栏透明度 translucent 默认是yes(iOS 7.0以后出现这个属性)
//全局设置取消透明度
[[UINavigationBar appearance] setTranslucent:NO];
//单个页面取消透明度
    self.navigationController.navigationBar.translucent = NO;

关于label文字俩端对齐

//NSTextAlignmentJustified 设置文字俩端对齐属性 (这个属性只支持Xcode6.0以上版本)
self.textDescribe.textAlignment = NSTextAlignmentJustified;

如何去掉导航栏下边横线和选项卡上边灰色横线

// 去掉导航栏下边横线
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init]
                                                  forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
    // 去掉选项卡上边的横线
    [self.tabBarController.tabBar setBackgroundImage:[UIImage new]];
    [self.tabBarController.tabBar setShadowImage:[UIImage new]];

今天就先写这些我问题 后续出现更多问题 再添加

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容