技巧1: 如何禁用UIButton的高亮效果
方法1: <pre><code>button.adjustsImageWhenHighlighted = NO;</code></pre>
方法2:Make your UIButton a custom button and then apply a UIImage background to it. It won't highlight or change when pressed
<pre><code>UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];</code></pre>
技巧2:如何禁用UITableViewCell的高亮效果,还可以相应事件
设置UITableViewCell的
cell.selectionStyle = UITableViewCellSelectionStyleNone;
技巧3:删除UINavigationViewController 的back button的title
<pre><code>[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];</code></pre>
技巧3:
修改导航栏标题的字体
跟iOS 6一样,我们可以使用导航栏的titleTextAttributes属性来定制导航栏的文字风格。在text attributes字典中使用如下一些key,可以指定字体、文字颜色、文字阴影色以及文字阴影偏移量:
UITextAttributeFont – 字体key
UITextAttributeTextColor – 文字颜色key
UITextAttributeTextShadowColor – 文字阴影色key
UITextAttributeTextShadowOffset – 文字阴影偏移量key
如下代码所示,对导航栏的标题风格做了修改:
<pre><code>
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
</code></pre>
技巧4: iOS release版本中去掉NSLog输出
<pre><code>
ifndef OPTIMIZE
define NSLog(...) NSLog(VA_ARGS)
else
define NSLog(...) {}
endif
</code></pre>
技巧5:
title和图片左右排列,默认情况下是图片在左,文字在右
<pre>
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, CGRectGetWidth(self.view.frame)/3, 50)];
[button setTitle:@"筛选" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
UIImage *image = [UIImage imageNamed:@"icon_filter_gray"];
[self.view addSubview:button];
</pre>
如果想让文字在左,图片在右可以加上如下几行代码:
<pre>
button.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
</pre>
网友评论