ios開發(fā)小技巧

[self.navigationController.view addSubview:bgView];

全屏的視圖層


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

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

self.automaticallyAdjustsScrollViewInsets = NO;

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

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

怎么像safari一樣滑動的時候隱藏navigationbar?

navigationController.hidesBarsOnSwipe = Yes

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

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

forBarMetrics:UIBarMetricsDefault];

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

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

// 設置系統(tǒng)默認導航條的顏色

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

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

}

else {

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

}

[self.navigationController.navigationBarsetTitleTextAttributes:

@{NSFontAttributeName:[UIFontsystemFontOfSize:19],

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

?

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

CSStickyHeaderFlowLayou

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

怎么把tableview里cell的小對勾的顏色改成別的顏色?

_mTableView.tintColor = [UIColor redColor];

本來我的statusbar是lightcontent的,結果用UIImagePickerController會導致我的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,重寫這個方法

- (void) drawPlaceholderInRect:(CGRect)rect {

[[UIColor blueColor] setFill];

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

}

?

實現(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];

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

//添加電話圖標按鈕

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

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

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

[btnPhone setBackgroundImage:image forState:UIControlStateNormal];

//點擊撥號按鈕直接撥號

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

[cell.contentView addSubview:btnPhone];? //cell是一個UITableViewCell

//定義點擊撥號按鈕時的操作

- (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為號碼字符串

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //撥號

}

設置時區(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];

}

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

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);

}

這個方法只在循環(huán)第一次被調(diào)用,所以不必擔心循環(huán)每次計算的問題。

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

[sark doSomething];

}];

只用一個pan手勢來代替UISwipegesture的各個方向?

?- (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中,如何檢測系統(tǒng)自帶ViewController手勢返回結束??

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

{

idtc=navigationController.topViewController.transitionCoordinator;

[tcnotifyWhenInteractionEndsUsingBlock:^(idcontext){

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

}];

}

?

?

?

?

?

?

?

?

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容