ios開發(fā)小技巧

[self.navigationController.view addSubview:bgView];

全屏的視圖層


自定義了leftBarbuttonItem左滑返回手勢(shì)失效了怎么辦?

ScrollView莫名其妙不能在viewController劃到頂怎么辦?

self.automaticallyAdjustsScrollViewInsets = NO;

怎么在不新建一個(gè)Cell的情況下調(diào)整separaLine的位置?

_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);

怎么像safari一樣滑動(dòng)的時(shí)候隱藏navigationbar?

navigationController.hidesBarsOnSwipe = Yes

導(dǎo)航條返回鍵帶的title太討厭了,怎么讓它消失!

?[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)

forBarMetrics:UIBarMetricsDefault];

更改系統(tǒng)默認(rèn)返回的《按鈕的顏色為白色

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];?

// 設(shè)置系統(tǒng)默認(rèn)導(dǎo)航條的顏色

if ([self.navigationController.navigationBarrespondsToSelector:@selector(setBarTintColor:)]) {

[self.navigationController.navigationBarsetBarTintColor:[UIColorblackColor]];

}

else {

[self.navigationController.navigationBarsetTintColor:[UIColorblackColor]];

}

[self.navigationController.navigationBarsetTitleTextAttributes:

@{NSFontAttributeName:[UIFontsystemFontOfSize:19],

NSForegroundColorAttributeName:[UIColorwhiteColor]}]; // 設(shè)置系統(tǒng)默認(rèn)title的顏色

?

CollectionView 怎么實(shí)現(xiàn)tableview那種懸停的header?

CSStickyHeaderFlowLayou

拉伸圖片的時(shí)候怎么才能讓圖片不變形倍权?1.UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];?

怎么把tableview里cell的小對(duì)勾的顏色改成別的顏色狠怨?

_mTableView.tintColor = [UIColor redColor];

本來(lái)我的statusbar是lightcontent的,結(jié)果用UIImagePickerController會(huì)導(dǎo)致我的statusbar的樣式變成黑色边锁,怎么辦锨匆??

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

{

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

?}

怎么把我的navigationbar弄成透明的而不是帶模糊的效果悟泵?

[self.navigationBar setBackgroundImage:[UIImage new]

forBarMetrics:UIBarMetricsDefault];

self.navigationBar.shadowImage = [UIImage new];

self.navigationBar.translucent = YES;

怎么改變uitextfield placeholder的顏色和位置港华?

繼承uitextfield脾歇,重寫這個(gè)方法

- (void) drawPlaceholderInRect:(CGRect)rect {

[[UIColor blueColor] setFill];

[self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];

}

?

實(shí)現(xiàn)自定義的狀態(tài)欄(遮蓋狀態(tài)欄)

CGRect frame = {{0, 0}, {320, 20}};

UIWindow* wd = [[UIWindow alloc] initWithFrame:frame];

[wd setBackgroundColor:[UIColor clearColor]];

[wd setWindowLevel:UIWindowLevelStatusBar];

frame = CGRectMake(100, 0, 30, 20);

UIImageView* img = [[UIImageView alloc] initWithFrame:frame];

[img setContentMode:UIViewContentModeCenter];

[img setImage:[UIImage imageNamed:@"00_0103.png"]];

[wd addSubview:img];

[wd makeKeyAndVisible];

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:2];

frame.origin.x += 150;

[img setFrame:frame];

[UIView commitAnimations];

?在程序中實(shí)現(xiàn)電話的撥打

//添加電話圖標(biāo)按鈕

UIButton *btnPhone = [[UIButton buttonWithType:UIButtonTypeCustom] retain];

btnPhone.frame = CGRectMake(280,10,30,30);

UIImage *image = [UIImage imageNamed:@"phone.png"];

[btnPhone setBackgroundImage:image forState:UIControlStateNormal];

//點(diǎn)擊撥號(hào)按鈕直接撥號(hào)

[btnPhone addTarget:self action:@selector(callAction:event:)forControlEvents:UIControlEventTouchUpInside];

[cell.contentView addSubview:btnPhone];? //cell是一個(gè)UITableViewCell

//定義點(diǎn)擊撥號(hào)按鈕時(shí)的操作

- (void)callAction:(id)sender event:(id)event{

NSSet *touches = [event allTouches];

UITouch *touch = [touches anyObject];

CGPoint currentTouchPosition = [touch locationInView:self.listTable];

NSIndexPath *indexPath = [self.listTable indexPathForRowAtPoint: currentTouchPosition];

if (indexPath == nil) {

return;

}

NSInteger section = [indexPath section];

NSUInteger row = [indexPath row];

NSDictionary *rowData = [datas objectAtIndex:row];

NSString *num = [[NSString alloc] initWithFormat:@"tel://%@

",number]; //number為號(hào)碼字符串

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //撥號(hào)

}

設(shè)置時(shí)區(qū)?

NSTimeZone *defaultTimeZone = [NSTimeZone defaultTimeZone];

NSTimeZone *tzGMT = [NSTimeZone timeZoneWithName:@"GMT"];

[NSTimeZone setDefaultTimeZone:tzGMT];

捕獲iphone通話事件?

CTCallCenter *center = [[CTCallCenter alloc] init];

center.callEventHandler = ^(CTCall *call)

{

NSLog(@"call:%@", call.callState);

}

如何判斷郵箱輸入的是否正確刻蟹??

- (BOOL) validateEmail: (NSString *) candidate {

NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";

NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];

return [emailTest evaluateWithObject:candidate];

}

如果在程序中想對(duì)某張圖片進(jìn)行處理的話(如得到某張圖片的一部分)怎么做逗旁??

UIImage *image = [UIImage imageNamed:filename];

CGImageRef imageRef = image.CGImage;

CGRect rect = CGRectMake(origin.x, origin.y ,size.width, size.height);

CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect);

UIImage *imageRect = [[UIImage alloc] initWithCGImage:imageRefRect];

倒序遍歷

NSArray和NSOrderedSet都支持使用reverseObjectEnumerator倒序遍歷,如:NSArray *strings = @[@"1", @"2", @"3"];

for (NSString *string in [strings reverseObjectEnumerator]) {

NSLog(@"%@", string);

}

這個(gè)方法只在循環(huán)第一次被調(diào)用舆瘪,所以不必?fù)?dān)心循環(huán)每次計(jì)算的問(wèn)題片效。

同時(shí),使用enumerateObjectsWithOptions:NSEnumerationReverse也可以實(shí)現(xiàn)倒序遍歷:[array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(Sark *sark, NSUInteger idx, BOOL *stop) {

[sark doSomething];

}];

只用一個(gè)pan手勢(shì)來(lái)代替UISwipegesture的各個(gè)方向?

?- (void)pan:(UIPanGestureRecognizer *)sender

{

typedef NS_ENUM(NSUInteger, UIPanGestureRecognizerDirection) {

UIPanGestureRecognizerDirectionUndefined,

UIPanGestureRecognizerDirectionUp,

UIPanGestureRecognizerDirectionDown,

UIPanGestureRecognizerDirectionLeft,

UIPanGestureRecognizerDirectionRight

};

static UIPanGestureRecognizerDirection direction = UIPanGestureRecognizerDirectionUndefined;

switch (sender.state) {

case UIGestureRecognizerStateBegan: {

if (direction == UIPanGestureRecognizerDirectionUndefined) {

CGPoint velocity = [sender velocityInView:recognizer.view];

BOOL isVerticalGesture = fabs(velocity.y) > fabs(velocity.x);

if (isVerticalGesture) {

if (velocity.y > 0) {

direction = UIPanGestureRecognizerDirectionDown;

} else {

direction = UIPanGestureRecognizerDirectionUp;

}

}

else {

if (velocity.x > 0) {

direction = UIPanGestureRecognizerDirectionRight;

} else {

direction = UIPanGestureRecognizerDirectionLeft;

}

}

}

break;

}

case UIGestureRecognizerStateChanged: {

switch (direction) {

case UIPanGestureRecognizerDirectionUp: {

[self handleUpwardsGesture:sender];

break;

}

case UIPanGestureRecognizerDirectionDown: {

[self handleDownwardsGesture:sender];

break;

}

case UIPanGestureRecognizerDirectionLeft: {

[self handleLeftGesture:sender];

break;

}

case UIPanGestureRecognizerDirectionRight: {

[self handleRightGesture:sender];

break;

}

default: {

break;

}

}

break;

}

case UIGestureRecognizerStateEnded: {

direction = UIPanGestureRecognizerDirectionUndefined;

break;

}

default:

break;

}

}

在ioS7中英古,如何檢測(cè)系統(tǒng)自帶ViewController手勢(shì)返回結(jié)束淀衣??

?-(void)navigationController:(UINavigationController*)navigationControllerwillShowViewController:(UIViewController*)viewControlleranimated:(BOOL)animated

{

idtc=navigationController.topViewController.transitionCoordinator;

[tcnotifyWhenInteractionEndsUsingBlock:^(idcontext){

NSLog(@"7:%i",[contextisCancelled]);

}];

}

?

?

?

?

?

?

?

?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市哺呜,隨后出現(xiàn)的幾起案子舌缤,更是在濱河造成了極大的恐慌箕戳,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,590評(píng)論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件国撵,死亡現(xiàn)場(chǎng)離奇詭異陵吸,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)介牙,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,157評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門壮虫,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人环础,你說(shuō)我怎么就攤上這事囚似。” “怎么了线得?”我有些...
    開封第一講書人閱讀 169,301評(píng)論 0 362
  • 文/不壞的土叔 我叫張陵饶唤,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我贯钩,道長(zhǎng)募狂,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,078評(píng)論 1 300
  • 正文 為了忘掉前任角雷,我火速辦了婚禮祸穷,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘勺三。我一直安慰自己雷滚,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,082評(píng)論 6 398
  • 文/花漫 我一把揭開白布吗坚。 她就那樣靜靜地躺著祈远,像睡著了一般。 火紅的嫁衣襯著肌膚如雪刻蚯。 梳的紋絲不亂的頭發(fā)上绊含,一...
    開封第一講書人閱讀 52,682評(píng)論 1 312
  • 那天,我揣著相機(jī)與錄音炊汹,去河邊找鬼。 笑死逃顶,一個(gè)胖子當(dāng)著我的面吹牛讨便,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播以政,決...
    沈念sama閱讀 41,155評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼霸褒,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了盈蛮?” 一聲冷哼從身側(cè)響起废菱,我...
    開封第一講書人閱讀 40,098評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后殊轴,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體衰倦,經(jīng)...
    沈念sama閱讀 46,638評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,701評(píng)論 3 342
  • 正文 我和宋清朗相戀三年旁理,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了樊零。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,852評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡孽文,死狀恐怖驻襟,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情芋哭,我是刑警寧澤沉衣,帶...
    沈念sama閱讀 36,520評(píng)論 5 351
  • 正文 年R本政府宣布,位于F島的核電站减牺,受9級(jí)特大地震影響厢蒜,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜烹植,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,181評(píng)論 3 335
  • 文/蒙蒙 一斑鸦、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧草雕,春花似錦巷屿、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,674評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至诫钓,卻和暖如春旬昭,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背菌湃。 一陣腳步聲響...
    開封第一講書人閱讀 33,788評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工问拘, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人惧所。 一個(gè)月前我還...
    沈念sama閱讀 49,279評(píng)論 3 379
  • 正文 我出身青樓骤坐,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親下愈。 傳聞我的和親對(duì)象是個(gè)殘疾皇子纽绍,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,851評(píng)論 2 361

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