UIButton和UILabel的常见设置方法

来源:互联网 发布:在线试衣软件 编辑:程序博客网 时间:2024/06/05 04:44

UIButton的常见设置方法

  • (void)setTitle:(NSString *)title forState:(UIControlState)state;
    设置按钮的文字
  • (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
    设置按钮的文字颜色

  • (void)setImage:(UIImage *)image forState:(UIControlState)state;
    设置按钮内部的小图片

  • (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;
    设置按钮的背景图片

设置按钮的文字字体(需要拿到按钮内部的label来设置)
btn.titleLabel.font = [UIFont systemFontOfSize:13];
注意: 不要通过btn.titleLabel.text来设置按钮文字, 而是通过setTitle:方法来设置按钮文字, 因为按钮文字分不同状态。

  • (NSString *)titleForState:(UIControlState)state;
    获得按钮的文字

  • (UIColor *)titleColorForState:(UIControlState)state;
    获得按钮的文字颜色

  • (UIImage *)imageForState:(UIControlState)state;
    获得按钮内部的小图片

  • (UIImage *)backgroundImageForState:(UIControlState)state;
    获得按钮的背景图片

UILable的常见设置方法

  • UILabel 的 font 属性
  • 创建UIFont 对象
  • (UIFont *)systemFontOfSize:(CGFloat)fontSize; 系统默认字体
  • (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; 粗体
  • (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; 斜体
  • 创建指定字体的 UIFont对象
0 0