美文网首页
iOS-产品要的UIView

iOS-产品要的UIView

作者: 木子影 | 来源:发表于2017-08-21 16:49 被阅读4次

1、Button上面图片,下面文字

attentionBtn.frame = .init(x: kScreenW-15.0-40.0, y: 30.0, width: 40.0, height: 46.0)
        attentionBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.center //先调整图片文字水平居中,再调整图片文字的位置
        attentionBtn.titleEdgeInsets = UIEdgeInsetsMake(attentionBtn.imageView!.frame.size.height, -attentionBtn.imageView!.frame.size.width, 0.0, 0.0)
        attentionBtn.imageEdgeInsets = UIEdgeInsetsMake(-attentionBtn.titleLabel!.frame.size.height, 0.0,0.0, -attentionBtn.titleLabel!.bounds.size.width)
        attentionBtn.titleLabel!.font = UIFont.systemFont(ofSize: 12)
        contentView.addSubview(attentionBtn)

2、tabbar中间的那个是整个图片,无需自定义,简单实现

if([childVc isKindOfClass:NSClassFromString(@"YXFLViewController")]){
          //就是这句,调整图片的位置,跟button差不多
           childVc.tabBarItem.imageInsets=UIEdgeInsetsMake(6, 0, -6, 0);

}

效果图:

效果图.png

3、设置UITextField中placeholder的颜色,方法有三种,第三种重写TextField的drawRect麻烦,就说前面两个。

方法一:利用富文本字符串
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"请输入占位文字" attributes:
    @{NSForegroundColorAttributeName:[UIColor redColor],
                 NSFontAttributeName:textField.font
         }];
    textField.attributedPlaceholder = attrString;
方法二:KVC
 [textField1 setValue:[UIColor greenColor] forKeyPath:@"_placeholderLabel.textColor"];

相关文章

网友评论

      本文标题:iOS-产品要的UIView

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