Tag: uibutton

如何用Objective-C更改多个UIButton颜色

我有一些使用的button,我想要一个有效的方式来改变所有的背景颜色,而不是一个一个地改变它或在AppDelegate上做。 我基本上想避免这个 buttonOne.backgroundColor = [UIColor BlueColor]; buttonTwo.backgroundColor = [UIColor BlueColor]; buttonThree.backgroundColor = [UIColor BlueColor]; buttonFour.backgroundColor = [UIColor BlueColor]; 没有在AppDelegate中做到这一点,有效的方法是什么。

在Disabale UIButton上

当禁用button。 不透明度降低到50%,有什么办法可以将不透明度降低到25%

如果从故事板创buildbutton,则更改子类中的UIButtontypes

如果我在故事板中创build一个UIButton并将其类指定为我创build的子类( HighlightTappedButton ),那么在子类中是否有方法将buttonType更改为Custom ? 我知道我可以在故事板中将types更改为Custom ,但是我不想每次都记得这样做。

设备旋转后的iOSbutton点击区域

旋转后,我遇到了几个button的问题。 在纵向模式下,button堆叠在屏幕的底部。 在风景中时,它们被移动并resize以并排在屏幕的底部。 这一切都很好,button的行为正确。 但是,如果手机然后旋转回肖像,button的点击区域是错误的 – 只有button的左边1/3是可点击的。 这是做旋转的代码。 (我在viewWillAppear中调用它,所以当视图显示的时候,它总是被执行,以防视图已经在横向上)。我已经把button放在了它们自己的内部视图中。 – (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { // determine our dimensions based on orientation CGRect mainRect = [[UIScreen mainScreen] bounds]; CGFloat maxWidthHeight = MAX(mainRect.size.width, mainRect.size.height); CGFloat minWidthHeight = MIN(mainRect.size.width, mainRect.size.height); CGFloat _windowWidth = (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) ? minWidthHeight : maxWidthHeight; // get the current sizes of the things we are moving […]

改变embedded到button的图像的颜色(Swift3)

我可以通过以下代码将UIButton的图像颜色从黑色更改为白色: extension UIImage { func maskWith(color: UIColor) -> UIImage { UIGraphicsBeginImageContextWithOptions(size, false, scale) let context = UIGraphicsGetCurrentContext()! context.translateBy(x: 0, y: size.height) context.scaleBy(x: 1.0, y: -1.0) context.setBlendMode(.normal) let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) context.clip(to: rect, mask: cgImage!) color.setFill() context.fill(rect) let newImage = UIGraphicsGetImageFromCurrentImageContext()! UIGraphicsEndImageContext() return newImage } } 我使用以下设置UIButton的图像的颜色: //creditCardBtn is […]

如何通过button显示图像? -迅速

我以编程方式创build一个UIButton ,并将标题,图像设置为以下代码。 问题是每当我点击button的图像被突出显示,但button的标题不。 所以,我想创build两者或没有animation效果。 以及我应该给约束或什么让图像正确的文本“分类” ?

自动调整UITableView的旋转宽度

我将UIButtons添加到位于分割视图控制器右侧的UIView。 没有任何自动设置,button文本将以横向方式完全显示。 当我旋转到纵向方向时,所有的button文本都被完全显示,但UIView的右侧有额外的空间,因为有更多的房地产可以使用。 我希望这些button在旋转时resize,以便利用整个宽度。 我试过设置: [button setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 有了这个,在纵向方向上存在相同的额外的房地产,但在横向方向,我得到了很多与“…”缩短文本的button, 如何才能做到这一点?

iOS – 从其超类设置UIButton目标和操作

我有2类ClassA:UIView ClassB:UIViewController 我在ClassA中有一个UIButton 该button在标题中声明,并作为A的@属性 UIButton *selectBtn; } @property (nonatomic, strong) UIButton *selectBtn; 在A类的.m文件中,button被初始化并显示在屏幕上 ClassB导入ClassA的头文件,并从它我试图设置目标和我的button与下面的动作 [ClassA.selectBtn addTarget:self action:@selector(getSomething:) forControlEvents:UIControlEventTouchUpInside]; 但我不断收到一个错误消息,说“属性”selectBtn“找不到对象的types”ClassA“ 我究竟做错了什么 ? 任何帮助或指导,非常感激

试图添加一个UIButton到一个UIView但得到NSInvalidArgumentException',原因:' – :无法识别

我想添加一个UIButton到一个UIView,但我在运行时得到这个错误。 NSInvalidArgumentException',原因:' – [UIView addSubView:]:无法识别 XCode也警告我说 实例方法'-addSubView:'未find(返回types默认为'id') 这是我的代码: UIView *trackPaneView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 100)] autorelease]; [trackPaneView setBackgroundColor:[UIColor blueColor]]; UIButton *testButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 10, 100, 30)]; [testButton setTitle:@"AWESOME" forState:UIControlStateNormal]; [trackPaneView addSubView:testButton]; //the error coming form this line

在Swift IOS中的UIButton查询

我有一个62,62平方的button。 我有一个40,40平方的形象。 我想在button中的图像(这是很容易和完成),但我希望它在button框架的顶部,我想在底部的一些文字。 所以看起来像这样: 任何想法如何迅速做到这一点? 我到目前为止: button.backgroundColor = UIColor(red: 0.13, green: 0.48, blue: 0.81, alpha: 1.0) button.tag = i button.imageView?.image button.setImage(image, forState: .Normal) button.setTitle("Test", forState: UIControlState.Normal) testingsetTitle,作为…forms来到图像的右侧。 任何人都可以build议?