UILabel和UIButton

Step--1:UILabel

1、基本用法

    //声明UILabel对象

    @property(nonatomic,strong) UILabel*label;

 // 初始化

 self.label= [[UILabelalloc] init];

 //背景色

 self.label.backgroundColor= [UIColorgrayColor];

 //设置frame

 self.label.frame= CGRectMake(20,20,200, 100);

 //设置文本内容

 self.label.text= @"In the evening one may praise the day.";

 //设置字体大小

 self.label.font= [UIFontsystemFontOfSize:17.0];

 //设置字体颜色

 self.label.textColor= [UIColorblueColor];

 //设置阴影偏移量

 //self.label.shadowOffset = CGSizeMake(1.0, 0.5);

 //设置阴影颜色

 //self.label.shadowColor = [UIColor purpleColor];

 //设置文本对其方式

 self.label.textAlignment= NSTextAlignmentCenter;

 //

 self.label.lineBreakMode= NSLineBreakByTruncatingMiddle;

 //设置行数 默认1 0代表自动换行

 //self.label.numberOfLines = 0;

 //设置自适应宽度

 //self.label.adjustsFontSizeToFitWidth = YES;

 //设置能否与用户交互

 self.label.userInteractionEnabled= YES;

 //设置文本是否可变

 self.label.enabled= YES;

 //设置文本是否高亮显示

 //self.label.highlighted = YES;

 //设置文本高亮显示颜色

 //self.label.highlightedTextColor = [UIColor redColor];

 //添加视图

    [self.viewaddSubview:self.label];

2、特殊用法(后续更新)

Step--1:UIButton

1、基本用法

   //1、创建

 /*

     UIButtonTypeCustom 自定义按钮类型

     UIButtonTypeSystem 系统默认按钮类型

     UIButtonTypeDetailDisclosure 细节展示按钮

     UIButtonTypeInfoLight Light 信息按钮

     UIButtonTypeInfoDark Dark 信息按钮

     UIButtonTypeContactAdd Light 信息按钮

     */

 UIButton*button = [UIButtonbuttonWithType:UIButtonTypeCustom];

 //2、常用属性

    button.frame= CGRectMake(20, 20, 100, 40);

    button.backgroundColor= [UIColorgrayColor];

 /*

     UIControlStateNormal 默认状态

     UIControlStateHighlighted 高亮状态

     UIControlStateDisabled 不可用状态

     UIControlStateSelected 选择状态

     */

 //设置对应状态的标题内容,默认为nil  - (void)setTitle:(NSString *)title forState:(UIControlState)state;

[button setTitle:@"按钮"forState:UIControlStateNormal];

 //设置对应状态的标题颜色 - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;

[button setTitleColor:[UIColorblueColor] forState:UIControlStateNormal];

 //设置对应状态的标题阴影颜色 - (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state;

[button setTitleShadowColor:[UIColoryellowColor] forState:UIControlStateNormal];

    //设置偏移量

     button.titleLabel.shadowOffset= CGSizeMake(0, -2);

 //设置对应状态的按钮背景图片 - (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;

[button setBackgroundImage:[UIImageimageNamed:@"icon"] forState:UIControlStateNormal];

 //设置对应状态的按钮的图片 - (void)setImage:(UIImage *)image forState:(UIControlState)state;

[button setImage:[UIImageimageNamed:@"icon"] forState:UIControlStateNormal];

 //设置字体大小

    button.titleLabel.font= [UIFontsystemFontOfSize:15];

 //设置字体自适应

    button.titleLabel.adjustsFontSizeToFitWidth= YES;

 //对齐方式

 /*

     contentVerticalAlignment

     contentHorizontalAlignment

     */

    button.contentVerticalAlignment= UIControlContentVerticalAlignmentCenter;

 //3、点击事件

 /*

     UIControlEventTouchDownRepeat

     多点触摸按下事件,点触计数大于1:用户按下第二、三、或第四根手指的时候。

     UIControlEventTouchDragInside

     当一次触摸在控件窗口内拖动时。

     UIControlEventTouchDragOutside

     当一次触摸在控件窗口之外拖动时。

     UIControlEventTouchDragEnter

     当一次触摸从控件窗口之外拖动到内部时。

     UIControlEventTouchDragExit

     当一次触摸从控件窗口内部拖动到外部时。

     UIControlEventTouchUpInside

     所有在控件之内触摸抬起事件。

     UIControlEventTouchUpOutside

     所有在控件之外触摸抬起事件(点触必须开始与控件内部才会发送通知)。

     UIControlEventTouchCancel

     所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者被上锁或者电话呼叫打断。

     UIControlEventTouchChanged

     当控件的值发生改变时,发送通知。用于滑块、分段控件、以及其他取值的控件。你可以配置滑块控件何时发送通知,在滑块被放下时发送,或者在被拖动时发送。

     UIControlEventEditingDidBegin

     当文本控件中开始编辑时发送通知。

     UIControlEventEditingChanged

     当文本控件中的文本被改变时发送通知。

     UIControlEventEditingDidEnd

     当文本控件中编辑结束时发送通知。

     UIControlEventEditingDidOnExit

     当文本控件内通过按下回车键(或等价行为)结束编辑时,发送通知。

     UIControlEventAlltouchEvents

     通知所有触摸事件。

     UIControlEventAllEditingEvents

     通知所有关于文本编辑的事件。

     UIControlEventAllEvents

     通知所有事件。

     */

[button addTarget:selfaction:@selector(actionClick:) forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:button];

//点击方法

- (void)actionClick:(UIButton*)click{

 //当前按钮上显示的标题

 NSString*currentTitle = click.currentTitle;

 //当前按钮上显示的标题的颜色

 UIColor*currentTitleColor = click.currentTitleColor;

 //当前按钮上显示的标题的阴影色

 UIColor*currentTitleShadowColor = click.currentTitleShadowColor;

 //当前按钮上显示的图像

 UIImage*currentImage = click.currentImage;

 //当前按钮上显示的背景图像

 UIImage*currentBackgroundImage = click.currentBackgroundImage;

 //

 UILabel*titleLabel = click.titleLabel;

 UIImageView*imageView = click.imageView;

 NSLog(@"currentTitle %@ currentTitleColor %@ currentTitleShadowColor %@ currentImage %@",currentTitle,currentTitleColor,currentTitleShadowColor,currentImage);

}

2、特殊用法(后续更新)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值