中間的提醒內容
指示器、HUD、遮蓋、蒙板
半透明的指示器如何實現?
指示器的alpha = 1.0
指示器的背景色是半透明的
創建顏色
直接創建對應的顏色
+ (UIColor*)blackColor;// 0.0 white
+ (UIColor*)darkGrayColor;// 0.333 white
+ (UIColor*)lightGrayColor;// 0.667 white
+ (UIColor*)whiteColor;// 1.0 white
+ (UIColor*)grayColor;// 0.5 white
+ (UIColor*)redColor;// 1.0, 0.0, 0.0 RGB
+ (UIColor*)greenColor;// 0.0, 1.0, 0.0 RGB
+ (UIColor*)blueColor;// 0.0, 0.0, 1.0 RGB
+ (UIColor*)cyanColor;// 0.0, 1.0, 1.0 RGB
+ (UIColor*)yellowColor;// 1.0, 1.0, 0.0 RGB
+ (UIColor*)magentaColor;// 1.0, 0.0, 1.0 RGB
+ (UIColor*)orangeColor;// 1.0, 0.5, 0.0 RGB
+ (UIColor*)purpleColor;// 0.5, 0.0, 0.5 RGB
+ (UIColor*)brownColor;// 0.6, 0.4, 0.2 RGB
+ (UIColor*)clearColor;// 透明色
根據RGB組合創建顏色
+ (UIColor*)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
漸變動畫
方式1:頭尾式
[UIViewbeginAnimations:nilcontext:nil];[UIViewsetAnimationDuration:2.0];/* 需要執行動畫的代碼 */[UIViewcommitAnimations];
方式2:block式
[UIViewanimateWithDuration:2.0delay:1.0options:kNilOptions animations:^{/* 需要執行動畫的代碼 */} completion:nil]// 1s后,再執行動畫(動畫持續2s)
按鈕
自定義按鈕:調整內部子控件的frame
方式1:實現titleRectForContentRect:和imageRectForContentRect:方法,分別返回titleLabel和imageView的frame
方式2:在layoutSubviews方法中設置
內邊距
// 設置按鈕內容的內邊距(影響到imageView和titleLabel)@property(nonatomic)UIEdgeInsetscontentEdgeInsets;
// 設置titleLabel的內邊距(影響到titleLabel)@property(nonatomic)UIEdgeInsetstitleEdgeInsets;
// 設置imageView的內邊距(影響到imageView)@property(nonatomic)UIEdgeInsetsimageEdgeInsets;
圖片拉伸
iOS5之前
// 只拉伸中間的1x1區域- (UIImage*)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
iOS5開始
- (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(鍵值監聽)
作用:監聽模型的屬性值改變
步驟
添加監聽器
// 利用b對象來監聽a對象name屬性的改變
[a addObserver:b forKeyPath:@"name"options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNewcontext:@"test"];
在監聽器中實現監聽方法
-(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change? ? context:(void*)context{NSLog(@"%@ %@ %@ %@", object, keyPath, change, context);}