UILabel & UITextFiled &UIButton & UIImageView

UILabel 标签

@property(nullable, nonatomic,copy)   NSString           *text;内容
@property(null_resettable, nonatomic,strong) UIFont      *font; 字体
@property(null_resettable, nonatomic,strong) UIColor     *textColor; 颜色
@property(nonatomic) NSInteger numberOfLines; 行数(0为允许任意行)
@property(nonatomic)        NSTextAlignment    textAlignment;对齐方式
UITextFiled 文本输入框

@property(nullable, nonatomic,copy)   NSString               *text; 内容
@property(nullable, nonatomic,strong) UIColor                *textColor;内
容颜色
@property(nullable, nonatomic,strong) UIFont                 *font; 字体
@property(nonatomic)        NSTextAlignment         textAlignment; 对齐方式
@property(nullable, nonatomic,copy)   NSString               *placeholder;提示信息
@property(nonatomic)        UITextBorderStyle       borderStyle;边框样式
UIButton 按钮

- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state; 设置指定状态的标题
- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR;设置指定状态的标题颜色
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;设置指定状态显示的图片
UIControl 控件

- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;添加监听事件
参数1:事件触发时执行对象
参数2:事件触发时执行指定对象中的指定方法
参数3:监听的事件类型
UIImageView 图片视图

- (instancetype)initWithImage:(nullable UIImage *)image;根据图片创建视图,视图的大小跟图片一样大
@property (nullable, nonatomic, strong) UIImage *image; 图片
UIImage 图片

+ (nullable UIImage *)imageNamed:(NSString *)name;根据名称生成图片
+ (nullable UIImage *)imageWithData:(NSData *)data;根据二进制生成图片

案例1(加法计算器)

加法计算器
案例2(小飞机)
//定义方向枚举
typedef NS_ENUM(NSInteger, DirType) {
    DIR_UP = 101,
    DIR_LEFT = 102,
    DIR_DOWN = 103,
    DIR_RIGHT = 104
};
@interface ViewController ()
//小飞机按钮
@property (nonatomic,weak) UIButton *planeButton;
@end
//设置界面
-(void)setUpUI{
    //设置背景视图
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];
    [self.view addSubview:iv];
    
    //设置飞机
    UIButton *planeButton = [[UIButton alloc] init];
    [planeButton setImage:[UIImage imageNamed:@"hero1"] forState:UIControlStateNormal];
    [planeButton setImage:[UIImage imageNamed:@"hero2"] forState:UIControlStateHighlighted];
    [self.view addSubview:planeButton];
    [planeButton sizeToFit];
    planeButton.center = self.view.center;
    planeButton.center = CGPointMake(self.view.center.x, self.view.center.y - 200);
    //记录变量
    self.planeButton = planeButton;
    
    //设置方向按钮
    CGFloat offset = 30;
    //方向按钮根基 偏移值CGPoint normal图片 helight图片 tag生成
    CGPoint center = CGPointMake(self.view.center.x, self.view.center.y + 180);
    [self creatButtonWith:@"top_normal" :@"top_highlighted" :CGPointMake(0, -offset) :DIR_UP :center];
    [self creatButtonWith:@"left_normal" :@"left_highlighted" :CGPointMake(-offset, 0) :DIR_LEFT :center];
    [self creatButtonWith:@"bottom_normal" :@"bottom_highlighted" :CGPointMake(0, offset) :DIR_DOWN :center];
    [self creatButtonWith:@"right_normal" :@"right_highlighted" :CGPointMake(offset, 0) :DIR_RIGHT :center];
    
}
//创建按钮并添加到视图
-(void)creatButtonWith:(NSString *)normalName :(NSString *)helightName :(CGPoint)offset :(NSInteger)tag :(CGPoint)center{
    UIButton *btn = [[UIButton alloc] init];
    [self.view addSubview:btn];
    [btn setImage:[UIImage imageNamed:normalName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:helightName] forState:UIControlStateHighlighted];
    btn.tag = tag;
    btn.frame = CGRectMake(0, 0, 40, 40);
    btn.center = CGPointMake(center.x + offset.x, center.y + offset.y);
    
    [btn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
}
//点击按钮
-(void)clickButton:(UIButton *)sender {
    //获取初始位置
    CGRect frame = self.planeButton.frame;
    //每次点击移动的距离
    CGFloat offset = 20;
    //修改位置
    switch (sender.tag) {
        case DIR_UP:
            frame.origin.y -= offset;
            break;
        case DIR_LEFT:
            frame.origin.x -= offset;
            break;
        case DIR_DOWN:
            frame.origin.y += offset;
            break;
        case DIR_RIGHT:
            frame.origin.x += offset;
            break;
            
        default:
            break;
    }
    //赋值
    self.planeButton.frame = frame;
}
@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文是对论文《The Z1: Architecture and Algorithms of Konrad Zuse...
    逸之阅读 10,030评论 15 12
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,805评论 19 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 32,295评论 18 399
  • 那在从前,忘了从何时间, 可我却记得地点, 只是一眼, 心里便有了你的容颜! 在那素色流年的某一天, 空灵婉转,歌...
    孤帆1314阅读 2,915评论 0 0
  • 胡来三年回顾之三 之15年 穿过 穿过父亲的山川,冰河,绿洲 置于一个古老荒芜的人世 低于草,低于羊, 低于藏原苦...
    胡来先生阅读 3,424评论 0 3

友情链接更多精彩内容