iOS開發(fā)中不常見的屬性設(shè)置

這是一篇相當(dāng)于梗顺,我開發(fā)過程中的一篇筆記吧∽荩可能比較雜亂粟誓,是我的第一篇文章。

1.應(yīng)用三方地圖軟件的時(shí)候:地圖功能顯示網(wǎng)格

出現(xiàn)這個(gè)的原因起意,可能是你的地圖apikey有問題鹰服,

2. button 文字對(duì)其

Button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//左對(duì)齊(UIControlContentHorizontalAlignment、CenterUIControlContentHorizontalAlignmentFill杜恰、UIControlContentHorizontalAlignmentRight)

Button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;//底部對(duì)其(UIControlContentVerticalAlignmentCenter、UIControlContentVerticalAlignmentFill仍源、UIControlContentVerticalAlignmentTop)


3設(shè)置button 上圖片心褐,文字的位置

button.imageEdgeInsets = UIEdgeInsetsMake(5,13,21,button.titleLabel.bounds.size.width);//設(shè)置image在button上的位置(上top,左left笼踩,下bottom逗爹,右right)這里可以寫負(fù)值,對(duì)上寫-5,那么image就象上移動(dòng)5個(gè)像素

button.titleEdgeInsets = UIEdgeInsetsMake(71, -button.titleLabel.bounds.size.width-50, 0, 0);//設(shè)置title在button上的位置(上top掘而,左left挟冠,下bottom,右right)

4.向上取整 ceilf()


5斷點(diǎn)續(xù)傳主要方法

/ /. 操作

AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];

_downloadOperation = op;

// 下載

// 指定文件保存路徑袍睡,將文件保存在沙盒中

NSArray docs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString path = [docs[0] stringByAppendingPathComponent:@“download.zip”];

op.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];

// 設(shè)置下載進(jìn)程代碼塊

bytesRead 當(dāng)前第一次讀取的字節(jié)數(shù)(100k)

totalBytesRead 已經(jīng)下載的字節(jié)數(shù)(4.9M)

totalBytesExpectedToRead 文件總大小(5M)

[op setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {

// 設(shè)置進(jìn)度條百分比

CGFloat precent = (CGFloat)totalBytesRead / totalBytesExpectedToRead;

NSLog(@"%f", precent);

_progressView.progress = precent;

}];


6//主動(dòng)退出程序


- (void)exitApplication {

[UIView beginAnimations:@"exitApplication" context:nil];

[UIView setAnimationDuration:0.5];

[UIView setAnimationDelegate:self];

// [UIView setAnimationTransition:UIViewAnimationCurveEaseOut forView:self.view.window cache:NO];

[UIView setAnimationTransition:UIViewAnimationCurveEaseOut forView:self.window cache:NO];

[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];

//self.view.window.bounds = CGRectMake(0, 0, 0, 0);

self.window.bounds = CGRectMake(0, 0, 0, 0);

[UIView commitAnimations];

}

- (void)animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

if ([animationID compare:@"exitApplication"] == 0) {

exit(0);

}

}


8設(shè)置tableViewCell間的分割線的顏色

[theTableView setSeparatorColor:[UIColor xxxx ]];


9.SDWebImage 清除圖片緩存

指定的

[[SDImageCache sharedImageCache] removeImageForKey:url];

[[SDImageCache sharedImageCache] removeImageForKey:url fromDisk:YES];

全部

[[SDImageCache sharedImageCache] clearDisk];

[[SDImageCache sharedImageCache] clearMemory];

忽略緩存知染,每次都直接下載方法

? ?UIImage *selectImage = [UIImage imageNamed:[NSString stringWithFormat:@"bottom_profile_active"]];

?? ?self.tabBarController.tabBar.selectedItem.selectedImage? = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

10.tableView正在滾動(dòng)停止?jié)L動(dòng)

CGPoint offset = self.tableView.contentOffset;

(self.tableView.contentOffset.y > 0) ? offset.y-- : offset.y++;

[self.tableView setContentOffset:offset animated:NO];

另外://在willDisplayCell里面處理數(shù)據(jù)能優(yōu)化tableview的滑動(dòng)流暢性

//獲取所有cell 的方法

NSArray*array = [self.tableView visibleCells];?

11.修改tabbar

設(shè)置文字顏色

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],

設(shè)置位子字體

NSForegroundColorAttributeName, [UIFont systemFontOfSize:18], NSFontAttributeName, nil]];

取到對(duì)應(yīng)nav

UIViewController *vc2 = self.tabBarController.viewControllers[2];

設(shè)置對(duì)應(yīng)圖片

UIImage * homenormalImage = [[UIImage imageNamed:@"bottom_tv_bg"]? imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

UIImage * homeselectImage = [[UIImage imageNamed:@"bottom_tv_bg"]? imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

vc2.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"" image:homenormalImage selectedImage:homeselectImage];

設(shè)置文字位置

[self.navigationController.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -5)];

設(shè)置圖片位置

self.navigationController.tabBarItem.imageInsets = UIEdgeInsetsMake(-2.5, 0, 2.5, 0);

12.GCD并列請(qǐng)求:

dispatch_group_t serviceGroup = dispatch_group_create();

// Start the first service

dispatch_group_enter(serviceGroup);

[self.configService startWithCompletion:^(ConfigResponse *results, NSError* error){

// Do something with the results

configError = error;

dispatch_group_leave(serviceGroup);

}];

// Start the second service

dispatch_group_enter(serviceGroup);

[self.preferenceService startWithCompletion:^(PreferenceResponse *results, NSError* error){

// Do something with the results

preferenceError = error;

dispatch_group_leave(serviceGroup);

}];

dispatch_group_notify(serviceGroup,dispatch_get_main_queue(),^{

// Assess any errors

NSError *overallError = nil;

if (configError || preferenceError)

{

// Either make a new error or assign one of them to the overall error

overallError = configError ?: preferenceError;

}

// Now call the final completion block

completion(overallError);

});

13.防止 timer? 阻塞

[[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:UITrackingRunLoopMode];

14.masonry? 等分控件

/**

*? 多個(gè)控件固定間隔的等間隔排列,變化的是控件的長(zhǎng)度或者寬度值

*

*? @param axisType? ? ? ? 軸線方向

*? @param fixedSpacing? ? 間隔大小

*? @param leadSpacing? ? 頭部間隔

*? @param tailSpacing? ? 尾部間隔

*/

- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType

withFixedSpacing:(CGFloat)fixedSpacing l

eadSpacing:(CGFloat)leadSpacing

tailSpacing:(CGFloat)tailSpacing;

/**

*? 多個(gè)固定大小的控件的等間隔排列,變化的是間隔的空隙

*

*? @param axisType? ? ? ? 軸線方向

*? @param fixedItemLength 每個(gè)控件的固定長(zhǎng)度或者寬度值

*? @param leadSpacing? ? 頭部間隔

*? @param tailSpacing? ? 尾部間隔

*/

- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType

withFixedItemLength:(CGFloat)fixedItemLength

leadSpacing:(CGFloat)leadSpacing

tailSpacing:(CGFloat)tailSpacing;


15.數(shù)據(jù)遍歷快速斑胜,高效方法

//enumerateObjectsUsingBlock 類似于for控淡,但是比for更快

[array enumerateObjectsUsingBlock:^(MyCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

[obj cellOffset];

}];


16.runtime 或者屬性

// 獲取對(duì)象里的屬性列表

objc_property_t * properties = class_copyPropertyList([instance

class], &outCount);

for (i = 0; i < outCount; i++) {

objc_property_t property =properties[i];

//? 屬性名轉(zhuǎn)成字符串

NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];

// 判斷該屬性是否存在

if ([propertyName isEqualToString:verifyPropertyName]) {

free(properties);

return YES;

}

}

free(properties);


17.如何獲取app? 網(wǎng)頁JS代碼? command+,? 進(jìn)入偏好設(shè)置止潘,? 高級(jí)打開菜單欄掺炭,然后safafi 開發(fā)-simulate-選擇你想要的。


18.一些干貨推薦

(1)圖片大全

http://findicons.com/

http://www.easyicon.net/

(2)大牛blog

博客地址 RSS地址

OneV's Den http://onevcat.com/atom.xml

破船之家 http://beyondvincent.com/atom.xml

NSHipster http://nshipster.cn/feed.xml

Limboy 無網(wǎng)不剩 http://feeds.feedburner.com/lzyy

唐巧的技術(shù)博客 http://blog.devtang.com/atom.xml

Lex Tang http://lexrus.com/feed.xml

念茜的博客 http://nianxi.net/feed.xml

Xcode Dev http://blog.xcodev.com/atom.xml

Ted's Homepage http://wufawei.com/feed

txx's blog http://blog.t-xx.me/atom.xml

Kevin Blog http://zhowkev.in/rss

阿毛的蛋疼地 http://www.xiangwangfeng.com/atom.xml

亞慶的 Blog http://billwang1990.github.io/atom.xml

Nonomori http://nonomori.farbox.com/feed

言無不盡 http://tang3w.com/atom.xml

Wonderffee's Blog http://wonderffee.github.io/atom.xml

I'm TualatriX http://imtx.me/feed/latest/

Cocoabit http://blog.cocoabit.com/atom.xml

nixzhu on scriptogr.am http://nixzhu.me/feed

不會(huì)開機(jī)的男孩 http://studentdeng.github.io/atom.xml

Nico http://blog.inico.me/atom.xml

阿峰的技術(shù)窩窩 http://hufeng825.github.io/atom.xml

answer_huang http://answerhuang.duapp.com/index.php/feed/

webfrogs http://blog.nswebfrog.com/feed/

代碼手工藝人 http://joeyio.com/atom.xml

Lancy's Blog http://gracelancy.com/atom.xml

I'm Allen http://www.imallen.com/atom.xml

Travis' Blog http://imi.im/feed

王中周的技術(shù)博客 http://wangzz.github.io/atom.xml

會(huì)寫代碼的豬 http://gaosboy.com/feed/atom/

克偉的博客 http://feed.cnblogs.com/blog/u/23857/rss

搖滾詩人 http://feed.cnblogs.com/blog/u/35410/rss

Luke's Homepage http://geeklu.com/feed/

蕭宸宇 http://iiiyu.com/atom.xml

Yuan博客 http://www.heyuan110.com/?feed=rss2

Shining IO http://shiningio.com/atom.xml

YIFEIYANG--易飛揚(yáng)的博客 http://www.yifeiyang.net/feed

KooFrank's Blog http://koofrank.com/rss

hello it works http://helloitworks.com/feed

碼農(nóng)人生 http://msching.github.io/atom.xml

玉令天下的Blog http://yulingtianxia.com/atom.xml

不掏蜂窩的熊 http://www.hotobear.com/?feed=rss2

貓·仁波切 https://andelf.github.io/atom.xml

煲仔飯 http://ivoryxiong.org/feed.xml

里脊串的開發(fā)隨筆 http://adad184.com/atom.xml

Chun Tips http://chun.tips/atom.xml

Why's blog - 汪海的實(shí)驗(yàn)室 http://blog.callmewhy.com/atom.xml

Kenshin Cui's Blog http://www.cnblogs.com/kenshincui/rss

技術(shù)哥的博客 http://suenblog.duapp.com/rss/

(3)很多優(yōu)秀的第三方庫

http://blog.csdn.net/yipanbo/article/details/40047735

(4)swift 學(xué)習(xí)

http://wiki.jikexueyuan.com/project/swift/

http://www.ioscookies.com? 三方插件

19 tableViewCell ?

UITableViewCell分割線左邊部分缺少一些的解決方法

-(void)viewDidLayoutSubviews {

if ([self.mytableview respondsToSelector:@selector(setSeparatorInset:)]) {

[self.mytableview setSeparatorInset:UIEdgeInsetsZero];

}

if ([self.mytableview respondsToSelector:@selector(setLayoutMargins:)])? {

[self.mytableview setLayoutMargins:UIEdgeInsetsZero];

}

}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

[cell setLayoutMargins:UIEdgeInsetsZero];

}

if ([cell respondsToSelector:@selector(setSeparatorInset:)]){

[cell setSeparatorInset:UIEdgeInsetsZero];

}

}


20 UIButton怎樣去掉高亮透明效果

- (void)setHighlighted:(BOOL)highlighted{

}

self.btn_loginNow.adjustsImageWhenDisabled = NO;

self.btn_loginNow.adjustsImageWhenHighlighted = NO;


21 報(bào)錯(cuò)clang

這個(gè)錯(cuò)誤一定是有重復(fù)的類凭戴,或者屬性 比如使用了 const

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末涧狮,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子么夫,更是在濱河造成了極大的恐慌者冤,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,372評(píng)論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件魏割,死亡現(xiàn)場(chǎng)離奇詭異譬嚣,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)钞它,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門拜银,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人遭垛,你說我怎么就攤上這事尼桶。” “怎么了锯仪?”我有些...
    開封第一講書人閱讀 162,415評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵泵督,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我庶喜,道長(zhǎng)小腊,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,157評(píng)論 1 292
  • 正文 為了忘掉前任久窟,我火速辦了婚禮秩冈,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘斥扛。我一直安慰自己入问,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,171評(píng)論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著芬失,像睡著了一般楣黍。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上棱烂,一...
    開封第一講書人閱讀 51,125評(píng)論 1 297
  • 那天租漂,我揣著相機(jī)與錄音,去河邊找鬼垢啼。 笑死窜锯,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的芭析。 我是一名探鬼主播锚扎,決...
    沈念sama閱讀 40,028評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼馁启!你這毒婦竟也來了驾孔?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,887評(píng)論 0 274
  • 序言:老撾萬榮一對(duì)情侶失蹤惯疙,失蹤者是張志新(化名)和其女友劉穎翠勉,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體霉颠,經(jīng)...
    沈念sama閱讀 45,310評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡对碌,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,533評(píng)論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了蒿偎。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片朽们。...
    茶點(diǎn)故事閱讀 39,690評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖诉位,靈堂內(nèi)的尸體忽然破棺而出骑脱,到底是詐尸還是另有隱情,我是刑警寧澤苍糠,帶...
    沈念sama閱讀 35,411評(píng)論 5 343
  • 正文 年R本政府宣布叁丧,位于F島的核電站,受9級(jí)特大地震影響岳瞭,放射性物質(zhì)發(fā)生泄漏拥娄。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,004評(píng)論 3 325
  • 文/蒙蒙 一瞳筏、第九天 我趴在偏房一處隱蔽的房頂上張望稚瘾。 院中可真熱鬧,春花似錦乏矾、人聲如沸孟抗。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽凄硼。三九已至,卻和暖如春捷沸,著一層夾襖步出監(jiān)牢的瞬間摊沉,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評(píng)論 1 268
  • 我被黑心中介騙來泰國(guó)打工痒给, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留说墨,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,693評(píng)論 2 368
  • 正文 我出身青樓苍柏,卻偏偏與公主長(zhǎng)得像尼斧,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子试吁,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,577評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容