當(dāng)后臺(tái)傳值類型為long
前端需要用NSString類型接收
當(dāng)需要與特定值進(jìn)行比較時(shí)茄袖,需要把該值用doubleValue轉(zhuǎn)化后與數(shù)值比較贤牛,不能用NSString類型直接比較困后,因?yàn)楹笈_(tái)可能傳出的值為0.00型的或者0.0型的等鹉梨,不能完全相等
Model *model = [Model alloc] init];
model.userID = dict[@"id"];
if ([model.userID doubleValue] == 0)
{
//做需要的操作
}
設(shè)置view的背景圖片
view.layer.constonts = (__bridge id)image.CGImage;
界面通常為tableView或者collocationView布局婴程。
(借鑒dzenbot/DZNEmptyDataSet)
當(dāng)視圖數(shù)據(jù)為空時(shí)晋辆,需顯示默認(rèn)視圖渠脉。
可以在tableView創(chuàng)建的cell個(gè)數(shù)的時(shí)候判斷是否有內(nèi)容,如果內(nèi)容為空瓶佳,顯示默認(rèn)視圖芋膘,否則移除。
待:此方法不是最優(yōu)化方法霸饲,需想出更一勞永逸的解決方法为朋。
向數(shù)組中插入多個(gè)元素
數(shù)組操作中不僅能插入一個(gè)元素,還能插入多個(gè)元素首位或者末尾
NSArray *addModel = @[kbOne,kbTwo];
NSRange range=NSMakeRange(0, addModel.count);
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
[self.modelsArray insertObjects:addModel atIndexes:indexSet];
裁剪圓形頭像
#pragma mark - 裁剪圓形頭像
- (UIImage *)imageWithClipImage:(UIImage *)image
borderWidth:(CGFloat)borderW
boderColor:(UIColor *)boderColor
{
//加載image
//UIImage *image = [UIImage imageNamed:imageName];
//開啟位圖上下文
CGSize roundSize = CGSizeMake(image.size.width + 2 * borderW, image.size.height + 2 *borderW);
UIGraphicsBeginImageContextWithOptions(roundSize, NO, 0.0);
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, roundSize.width,roundSize.height)];
[boderColor set];
[path fill];
//設(shè)置裁剪區(qū)域
CGRect clipRect = CGRectMake(borderW, borderW, image.size.width, image.size.height);
path = [UIBezierPath bezierPathWithOvalInRect:clipRect];
[path addClip];
//繪制圖片
[image drawAtPoint:CGPointMake(borderW, borderW)];
//從上下文中取出新的圖片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//結(jié)束上下文
UIGraphicsEndImageContext();
//顯示新圖片
//self.iconImageView.image = newImage;
return newImage;
}
UIImageView旋轉(zhuǎn)
//需要注意厚脉,這里之所以用(0.000001 - M_PI),是因?yàn)閠ransform動(dòng)畫旋轉(zhuǎn)會(huì)選擇最近的路徑進(jìn)行旋轉(zhuǎn)习寸,默認(rèn)是順時(shí)針,如果直接選擇- M_PI傻工,那么箭頭只會(huì)順時(shí)針旋轉(zhuǎn)融涣,不會(huì)逆時(shí)針旋轉(zhuǎn)
// 使用了(0.000001 - M_PI),那么它會(huì)選擇近的路徑旋轉(zhuǎn)精钮,就不會(huì)順時(shí)針旋轉(zhuǎn)了
//大部分APP的下拉刷新基本都是箭頭逆時(shí)針回旋,并不是一直順時(shí)針旋轉(zhuǎn)
CGFloat angle = 0.000001 - M_PI ;
self.headerBtn.imageView.transform = CGAffineTransformMakeRotation(angle);
UIEdgeInsets和UIOffsets
UIOffset
view距離父視圖superView的邊距
UIEdgeInsets內(nèi)邊距
view內(nèi)的content距離view的邊距
UIEdgeInsets是什么剃斧?
typedef struct UIEdgeInsets {
CGFloat top, left, bottom, right; // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
} UIEdgeInsets;
三個(gè)UIEdgeInsets屬性
@property(nonatomic) UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // default is UIEdgeInsetsZero
@property(nonatomic) UIEdgeInsets titleEdgeInsets; // default is UIEdgeInsetsZero
@property(nonatomic) UIEdgeInsets imageEdgeInsets; // default is UIEdgeInsetsZero
提示:UI_APPEARANCE_SELECTOR標(biāo)記的屬性都支持通過(guò)外觀代理來(lái)定制轨香。
舉例,設(shè)置UIButton的contentEdgeInsets屬性幼东,可以直接調(diào)用:
[[UIButton appearance] setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
或者
button.imageEdgeInsets = UIEdgeInsetsMake(0,0,0,0);
tableview的contentOffset和contentInset
@property(nonatomic)CGPoint contentOffset; // default CGPointZero
@property(nonatomic)CGSize contentSize; // default CGSizeZero
@property(nonatomic)UIEdgeInsets contentInset;// default UIEdgeInsetsZero. add additional scroll area around content
contentSize
表示的是內(nèi)容區(qū)域的大小
contentOffset
是scrollview當(dāng)前顯示區(qū)域頂點(diǎn)相對(duì)于frame頂點(diǎn)的偏移量臂容,可以理解為contentview的頂點(diǎn)相對(duì)于scrollerVIew的frame的偏移量。
contentInset
表示contentView.frame.orgin與scrollerView.frame.orgin的關(guān)系根蟹∨迹可以類比于css里的padding。
參考contentSize简逮、contentOffset和contentInset的圖解辨別
UIButton之圖片球散、文字
參考UIButton 的 imageEdgeInsets 和 titleEdgeInsets
UIScrollerView偏移問(wèn)題
// public var automaticallyAdjustsScrollViewInsets: Bool // Defaults to YES
// 這個(gè)是scrollview自動(dòng)調(diào)整.當(dāng)scrollview是第一個(gè)view時(shí),系統(tǒng)會(huì)自動(dòng)調(diào)整,否則不會(huì)自動(dòng)調(diào)整64
view.automaticallyAdjustsScrollViewInsets = false
// 去掉自動(dòng)調(diào)整后,我們可以手動(dòng)將tableview的contentInset調(diào)整64,就能完成我們的需求
tableView.contentInset = UIEdgeInsets(top: 64, left: 0, bottom: 0, right: 0)
當(dāng)有tabBarController時(shí),推出下一個(gè)界面時(shí),隱藏tabbar*
hidesBottomBarWhenPushed = true
HTTP類封裝:判斷用戶權(quán)限、是否登陸操作
需要封裝一個(gè)HTTP相關(guān)的類散庶,在收到后臺(tái)的初始數(shù)據(jù)時(shí)進(jìn)行處理蕉堰,然后再封裝后傳出去