8-18 UIButton UImageView UIView
来源:互联网 发布:工程造价软件免费版 编辑:程序博客网 时间:2024/04/29 16:05
UIButton *button1 = [[UIButton alloc] init];
//设置字体大小
button1.titleLabel.font = [UIFont systemFontOfSize:20];
//设置selected属性强制让按钮处于选中状态
button1.selected = YES;//设置enabled属性强制按钮可用与否
button1.enabled = NO;//参数red green blue的取值范围为0-1
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;//为按钮添加点击事件
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;//随机颜色
UIColor *color = [UIColor colorWithRed:(arc4random()%256)/255.0 green:(arc4random()%256)/255.0 blue:(arc4random()%256)/255.0 alpha:1];
UILabel
//设置文本对齐方式
textAlignment属性
//UIImage与UIImageView,UIImage是用来加载图片,UIImageView更像是一个容器用来显示图片
UIImage *bg = [UIImage imageNamed:@"map.png”]; UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)]; bgView.image = bg; [self.view addSubview:bgView];
//将多张图片连续显示以达到动画的效果
UIImageView *penguin = [[UIImageView alloc] initWithFrame:CGRectMake(160,200,42,46)];//保证动画一开始就有一张图片显示
//imagesArr数组存放的是所有的图片
penguin.image = [imagesArr firstObject];
//给企鹅视图添加一组动画图片
//设置按钮tag,在点击事件中获得penguin这个imageView
penguin.animationImages = imagesArr; penguin.tag = 1000
//设置动画执行一次的时间
penguin.animationDuraion = 1;
[self.view addSubView:penguin];//设置按钮点击动画运行
- (void)onClick:(UIButton *)bt{ //根据tag和父视图获取子视图 viewWithTag: UIImageView *penguin = (UIImageView *)[self.view viewWithTag:1000]; //判断视图动画有没有在运行 if (penguin.isAnimating) { //运行 我就终止动画 [penguin stopAnimating]; penguin.frame = CGRectMake(160, 200, 42, 46); //销毁当前定时器 [animationTimer invalidate]; //设置成开始 当停止时 [bt setTitle:@"开始" forState:UIControlStateNormal]; }else{ //没在运行 开始动画 [penguin startAnimating]; /** * 使用类方法得到一个定时器的对象 * * @param go 参数1 回调方法调用的频率 参数2 回调函数对应的类的对象 参数3 定期回调的函数 参数4 参数3 是否要携带参数 参数5 是否循环执行 * * @return NSTimer */ animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(go) userInfo:nil repeats:YES]; //按钮设置 停止 [bt setTitle:@"停止" forState:UIControlStateNormal]; }}
//让penguin走起
- (void)go{ UIImageView *penguin = (UIImageView *)[self.window viewWithTag:1000]; //改坐标 penguin.frame = CGRectMake(penguin.frame.origin.x - 2, penguin.frame.origin.y, penguin.frame.size.width, penguin.frame.size.height);}
0 0
- 8-18 UIButton UImageView UIView
- UIView UILabel UITextField UIButton
- UIButton切换UIView
- UIView,UILabel,UIButton,
- UIButton,UIView,UITextField
- UIWindow UIView UILable UIButton
- UIView,UILabel,UITextField,UIButton使用方法
- UIButton和UIView的区别
- UIView UIButton UIImageView 添加事件
- IOS初级:UIView和UIButton
- UIView/UIButton 设置圆角
- Swift - UIView,UILabel,UIButton,UIImageView
- UIView UILabel UIButton知识整理
- 有关UIView,UIButton,UITabBarItem,UITabBarController的基础
- 自定义UIView中的UIButton无法显示
- UIView视图层级,Label, TextField,UIButton
- UIView中添加UIButton不能相应
- UIView UILabel UITextFiled UIButton UIControlView UIAlertView
- 自定义注解与mysql整合过滤查询实现
- 多态详解
- eclipse通过Remote Java Application调试Uiautomator的方法
- Root of AVL Tree (25)
- JPA相关注解
- 8-18 UIButton UImageView UIView
- android Dialog和EditText
- Myeclipse快捷键介绍
- 将正在运行的项目war包重命名后再恢复原名造成问题的疑问
- 关于volley的一点自己的理解
- JPA测试实例
- 算菜价
- 怪诞行为学 读书笔记
- CNN训练中的技巧