美文网首页
总结2017.6.23

总结2017.6.23

作者: 破夕_____________ | 来源:发表于2017-06-23 08:53 被阅读7次

    关于Button

    //设置圆角和颜色
    
    业界对于圆角优化很多方式,大家可以搜一下相关文章。本文只针对UILabel的cornerRadius方式进行讲解。
    先说一下cornerRadius属性,它是影响layer显示的backgroundColor和border,对layer的contents不起作用。
    对于不需要设置label的backgroundColor,只设置borderWidth、borderColor的label,直接设置cornerRadius,不需要设置masksToBounds = YES,就可以实现圆角功能。
    对于需要同时设置label的backgroundColor时,直接设置cornerRadius是不能正常显示圆角的,
    原因是:UILabel设置backgroundColor的行为,不再是设定layer的背景色而是为contents设置背景色。所以解决方式是我们不去设置label的backgroundColor,而是直接设置label.layer.backgroundColor,这样就可以实现单独设置cornerRadius,显示圆角的效果。
    UILabel *tagLabel = [UILabel new];tagLabel.text = @"减";
    tagLabel.textColor = [UIColor whiteColor];
    tagLabel.font = [UIFont systemFontOfSize:12];
    tagLabel.layer.backgroundColor = [UIColor greenColor].CGColor;
    tagLabel.layer.cornerRadius = 2;
    
    
    

    文字大小自适应

    
    
    1、确定Label或Button的字体大小,使其宽度自适应
    
    UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)];
    contentLabel.font = [UIFont systemFontOfSize:15];//-------->定义Font的大小
    contentLabel.backgroundColor = [UIColor redColor];
    contentLabel.text = @"我已知晓,且已阅读并同意以上条款";
    [contentLabel sizeToFit];//-------->注意和上面一句代码顺序不能颠倒
    [self.View addSubview:contentLabel];
    
    2、确定Label或Button的宽度,使字体大小自适应
    
    //无需自己设置字体大小
    UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)];
    contentLabel.backgroundColor = [UIColor redColor];
    contentLabel.text = @"我已知晓,且已阅读并同意以上条款";
    contentLabel.adjustsFontSizeToFitWidth = YES;//默认为NO-------->注意和上面一句代码顺序不能颠倒
    [self.View addSubview:contentLabel];
    
    如果是Button的话,和上面一样,只有一点小小的区别:
    
    [button.titleLabel sizeToFit];
    button.titleLabel.adjustsFontSizeToFitWidth = YES;
    
    
    

    常用的宏

    #define KSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
    #define KSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
    
    

    颜色的宏(随机色和自定义颜色)

    
    // 1.获得RGB颜色
    #define JMColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
    
    //2.随机色
    #define RandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1]
    
    
    

    关于cell和tableView

    //选中时没有颜色效果
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
    

    相关文章

      网友评论

          本文标题:总结2017.6.23

          本文链接:https://www.haomeiwen.com/subject/wlwqcxtx.html