中间的提醒内容
- 指示器、HUD、遮盖、蒙板
- 半透明的指示器如何实现?
- 指示器的alpha = 1.0
- 指示器的背景色是半透明的
创建颜色
+ (UIColor *)blackColor;
+ (UIColor *)darkGrayColor;
+ (UIColor *)lightGrayColor;
+ (UIColor *)whiteColor;
+ (UIColor *)grayColor;
+ (UIColor *)redColor;
+ (UIColor *)greenColor;
+ (UIColor *)blueColor;
+ (UIColor *)cyanColor;
+ (UIColor *)yellowColor;
+ (UIColor *)magentaColor;
+ (UIColor *)orangeColor;
+ (UIColor *)purpleColor;
+ (UIColor *)brownColor;
+ (UIColor *)clearColor;
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
渐变动画
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView commitAnimations];
[UIView animateWithDuration:2.0 delay:1.0 options:kNilOptions animations:^{
} completion:nil]
按钮
- 自定义按钮:调整内部子控件的frame
- 方式1:实现titleRectForContentRect:和imageRectForContentRect:方法,分别返回titleLabel和imageView的frame
- 方式2:在layoutSubviews方法中设置
- 内边距
@property(nonatomic) UIEdgeInsets contentEdgeInsets;
@property(nonatomic) UIEdgeInsets titleEdgeInsets;
@property(nonatomic) UIEdgeInsets imageEdgeInsets;
图片拉伸
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets;
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode;
拷贝
- 实现拷贝的方法有2个
- copy:返回不可变副本
- mutableCopy:返回可变副本
- 普通对象实现拷贝的步骤
- 遵守NSCopying协议
- 实现-copyWithZone:方法
KVC
- 全称:Key Value Coding(键值编码)
- 赋值
- (void)setValue:(id)value forKey:(NSString *)key;
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath;
- (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues;
- (id)valueForKey:(NSString *)key;
- (id)valueForKeyPath:(NSString *)keyPath;
- (NSDictionary *)dictionaryWithValuesForKeys:(NSArray *)keys;
KVO
- 全称:Key Value Observing(键值监听)
- 作用:监听模型的属性值改变
- 步骤
- 添加监听器
objc
// 利用b对象来监听a对象name属性的改变
[a addObserver:b forKeyPath:@"name" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:@"test"];
- 在监听器中实现监听方法
objc
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"%@ %@ %@ %@", object, keyPath, change, context);
}