一,通过按钮的事件来设置背景色 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - (void)viewDidLoad {     [super viewDidLoad];           UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 100, 50)];     [button1 setTitle:@"button1"…
我们知道直接在Storyboard中设置按钮的背景色是不能根据不同状态来更改的,那问题来了,如果我们需要在不同的状态下(比如按钮没有被按下或者被按下),使得按钮呈现不同的背景色怎么办? 比如上图左边是按钮没有被按下时的背景色,右边是按钮被按下时的背景色. 第一种方案 我们知道按钮的Image属性可以在不同的状态下设置不同的图片,那最直观的办法就是提供两种背景色的图片,然后直接在Storyboard上通过设置不同状态下Image属性的值来达到目的. 但是这种方案最不好的地方就在于需要提供很多仅仅是…
创建button设置可以折行显示 - (void)viewDidLoad { [super viewDidLoad]; UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(20, 30, 150, 70)]; [self.view addSubview:button]; [button setTitle:@"button" forState:UIControlStateNormal]; [button setTi…
参考自:原文地址(内容与原文并无区别,只是自己以后方便使用整理了一下) 1.UIButton的background是不支持在针对不同的状态显示不同的颜色. 2.UIButton的backgroundImage是针对不同的状态的,所以思路就是在不同状态下的的时候,生成指定颜色的纯色图片. 关键代码: /** *  设置不同状态下的背景色 * *  @param backgroundColor 背景色 *  @param state           状态 */ - (void)setBackgr…
UICollectionViewCell选中高亮状态 //设置点击高亮和非高亮效果! - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtI…
最近开发中遇到的问题汇总 有段时间没有归纳开发中遇到的一些问题了,今天就写一下之前开发中遇到的几个问题.希望这 篇文章能让读者在以后的开发中少走弯路.本文将依次介绍<UIButton在Disabled状态下标题混乱的问题>.<含软连字符的字符串计算显示长度 的问题>和<UINavigationBar左右两边按钮可同时点击的问题>. UIButton在Disabled状态下标题混乱的问题 你应该知道,UIButton的Disabled状态下标题在没有设定的时候,取Norm…
MJRefresh地址 //  代码地址: https://github.com/CoderMJLee/MJRefresh//  代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 MJRefresh默认情况下只能设置MJRefreshStateNoMoreD…
objc可以用通过重写setHighlighted方法来达到当按钮选中时的高亮状态 -(void)setHighlighted:(BOOL)highlighted{ } swift中取消高亮状态 override var isHighlighted: Bool { set{ } get { return false } }…
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state { [self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state]; } + (UIImage *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f,…
一,设置单选效果 - (void)selectedBtnPress:(UIButton*)sender { //首先把原来按钮的选中效果消除 for (int i=0;i<num;i++) {//num为总共设置单选效果按钮的数目 UIButton *btn = (UIButton*)[view viewWithTag:i];//view为这些btn的父视图 btn.selected = NO; } sender.selected = YES;//sender.selected = !sende…