常见的几种UIView

2016-04-10  本文已影响196人  游某人

UIView常见控件

UILabel

UIImageView

图片类UIImage

UIButton

Storyboard到代码的转换

点我啊.png
// 创建一个自定义的按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
// 默认状态的背景
[btn setBackgroundImage:[UIImage imageNamed:@"btn_01"] forState:UIControlStateNormal];
// 默认状态的文字
[btn setTitle:@"点我啊" forState:UIControlStateNormal];
// 默认状态的文字颜色
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

课堂小语法点

imageView.frame.size = imageView.image.size;
CGRect tempFrame = imageView.frame;
tempFrame.size = imageView.image.size;
imageView.frame = tempFrame;

修改frame的3种方式

imageView.frame = CGRectMake(100, 100, 200, 200);
CGRect tempFrame = imageView.frame;
tempFrame.origin.x = 100;
tempFrame.origin.y = 100;
tempFrame.size.width = 200;
tempFrame.size.height = 200;
imageView.frame = tempFrame;
imageView.frame = (CGRect){{100, 100}, {200, 200}};
mainBundle.png
[abc performSelector:@selector(stand:) withObject:@"123" afterDelay:10];
// 10s后自动调用abc的stand:方法,并且传递@"123"参数
// 创建一个音频文件的URL(URL就是文件路径对象)
NSURL *url = [[NSBundle mainBundle] URLForResource:@"音频文件名" withExtension:@"音频文件的扩展名"];
// 创建播放器
self.player = [AVPlayer playerWithURL:url];
// 播放
[self.player play];

}
```

音乐播放器

音乐音乐

关于内存管理

上一篇 下一篇

猜你喜欢

热点阅读