您的位置:首页 > 移动开发 > IOS开发

iOS你不知道的事①

2014-11-04 19:44 155 查看
一下内容 全是本人的心血总结 不喜勿喷

1.改变系统tabbar字体颜色

iOS5 [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f],UITextAttributeFont,[UIColor yellowColor],UITextAttributeTextColor,[UIColor redColor],UITextAttributeTextShadowColor,[NSValue
valueWithUIOffset:UIOffsetMake(0.0f,1.0f)],UITextAttributeTextShadowOffset,nil] forState:UIControlStateNormal];

iOS7 [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor orangeColor] } forState:UIControlStateSelected];

2.自定义导航栏左右两边的按钮图片

UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];

[leftBtn setBackgroundImage:[UIImage imageWithNamed:@"navigationbar_friendsearch"] forState:UIControlStateNormal];

[leftBtn setBackgroundImage:[UIImage imageWithNamed:@"navigationbar_friendsearch_highlighted"] forState:UIControlStateHighlighted];

leftBtn.frame = (CGRect){CGPointZero,leftBtn.currentBackgroundImage.size};

//或者

// leftBtn.frame = CGRectMake(0, 0, leftBtn.currentBackgroundImage.size.width, leftBtn.currentBackgroundImage.size.height);

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];

导航栏文字颜色设置

self.navigationItem.rightBarButtonItem.tintColor=[UIColor orangeColor];

3.1设置颜色 为指定的图片

……. = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1.png"]];

3.2 禁止pageControl 点击旁边是 会进行翻页的鲜果

_pageControl.userInteractionEnabled = NO;

3.3 按钮Button内部结构

按钮的左边是一个Image 右边是一个label

例如:

btn.selected = YES;//本身就有一个选中的属性 当选中时可以换一个image 等等

[btn setTitle:@"分享给大家" forState:UIControlStateNormal];

[btn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];

[btn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];

[btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);//设置title 上左下右的间距

checkbox.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);//设置图片 上左下右的间距

4.//去掉cell之间的线条

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

字符串替换

NSString *count = @"4.0万";

[count stringByReplacingOccurrencesOfString:@".0" withString:@""];

5.时间格式转换(此法仅适用于mark系统 不适于UI界面)

Fri Oct 10 17:19:06 +0800 2014

转成 2014-10-10 17:19:06 +0800

方法

NSDate *time = [NSDate dateWithNaturalLanguageString:@"Fri Oct 10 17:19:06 +0800 2014"];

NSLog(@"time is %@",time);

打印结果: time is 2014-10-10 17:19:06 +0800

6.//scrollView使用 使上面的UI控件从 y->0 开始;

self.automaticallyAdjustsScrollViewInsets = NO;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: