前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS_UIButton 简单操作

iOS_UIButton 简单操作

作者头像
全栈程序员站长
发布2022-07-07 17:45:34
2630
发布2022-07-07 17:45:34
举报

大家好,又见面了,我是全栈君。

UIButton 风格

代码语言:javascript
复制
typedef NS_ENUM(NSInteger, UIButtonType) {
    UIButtonTypeCustom = 0,                         // no button type
    UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),  // standard system button

    UIButtonTypeDetailDisclosure,
    UIButtonTypeInfoLight,
    UIButtonTypeInfoDark,
    UIButtonTypeContactAdd,

    UIButtonTypeRoundedRect = UIButtonTypeSystem,   // Deprecated, use UIButtonTypeSystem instead
};

简单操作

代码语言:javascript
复制
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.tag = 100; // 给 Button 加入标记 在不同的方法中使用同一个控件
    button.frame = CGRectMake(30, 170, 200, 40);
    [self.window addSubview:button];

    // 设置按钮文字。须要设置状态
    [button setTitle:@"按钮" forState:UIControlStateNormal];
// [button setTitle:@"Hello" forState:UIControlStateHighlighted];

    [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; // 给字体设置颜色 

    button.showsTouchWhenHighlighted = YES; // 高亮

    // 给button绑定事件
    [button addTarget:self // 接受消息的对象
               action:@selector(buttonAction:) // 发送的消息
     forControlEvents:UIControlEventTouchUpInside]; // 触发的方式

Button 方法

代码语言:javascript
复制
- (void) buttonAction
{
    NSLog(@"咔");
    // 通过 tag 。从父类视图中获取button
    UIButton *btn = (UIButton *)[self.window viewWithTag:100];
    ;
    // 让 Button 失效
    ;
}


- (void) buttonAction:(UIButton *)sender
{
    sender.backgroundColor = [UIColor redColor];
}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116488.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • UIButton 风格
  • 简单操作
  • Button 方法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档