草庐IT

uibuttons

全部标签

ios - 如何在快速点击时更改 UIButton 的背景颜色?

ViewController:UIViewController{@IBActionfunclike(sender:AnyObject){like(backgroundColor!)=UIColor.greenColor()}}我想改变UIbutton"likebutton"的颜色:白色是默认的“未点击或不像”点击时为绿色。如何使用Swift更改按钮的背景颜色? 最佳答案 按钮不是like--那是方法的名称。您可以通过sender访问该按钮。@IBActionfunclike(sender:AnyObject){(senderasUI

ios - 在透明部分不可点击的 Swift 中创建不规则的 UIButton

我正在制作一个饼图,其中每个扇区都是一个带有背景图像的单独按钮,但UIButton具有矩形形状并且所有按钮重叠。有没有办法让UIButton成为不规则图像的精确形状(在Swift中),这样就不会发生这种情况?任何帮助将不胜感激 最佳答案 您可以使用UIBezierPath或CGPath来定义您的饼图部分并使用它们的containsPoint:或CGPathContainsPoint检测触摸 关于ios-在透明部分不可点击的Swift中创建不规则的UIButton,我们在StackOver

ios - 折叠隐藏的 UIButton

在我的代码中,如果该按钮的数据源不包含值,我会使用UIButton.hidden在我的页面上隐藏各种UIButton。例如,企业可能有也可能没有URL。在我的应用程序中,如果企业有网站,我会将其加载到按钮的标题中,以便用户可以单击按钮并转到企业的网站。如果公司没有网站,我会隐藏按钮。挑战在于按钮即使在隐藏时也似乎占用了屏幕空间。我什至尝试了以下代码,但按钮仍然占用页面空间:btnURL.frame.size.height=0btnURL.frame.size.width=0btnURL.setTitle("",forState:.Normal)btnURL.hidden=true关于如

ios - UIButton 文本仅在触摸时出现

我设置了一个UIButton如下:letscanButton=UIButton()funcsetUpScanButton(scanButton:UIButton)->(){scanButton.addTarget(self,action:"goToScanner",forControlEvents:UIControlEvents.TouchUpInside)scanButton.backgroundColor=UIColor.greenColor()scanButton.setTitleColor(UIColor.blackColor(),forState:UIControlState

ios - UIButton 自动调整 Button 字体大小 Swift

我尝试做一些测验,但我的回答按钮有问题。简单的事实:文本太长,我尝试使用不同的方法为单元格自动调整它。我现在的状态:forbtninbtnArr{btn.titleLabel!.minimumScaleFactor=0.3btn.titleLabel!.numberOfLines=0btn.titleLabel!.adjustsFontSizeToFitWidth=truebtn.titleLabel?.baselineAdjustment=UIBaselineAdjustment.AlignCenters//btn.contentEdgeInsets=UIEdgeInsets(top

swift - 在 Swift 中从 UIButton (UIColor) backgroundColor 获取 RGB 颜色

我有三个UIButtons,每个都有不同的(UIColor)backgroundColor;例如,一个UIButton的backgroundColor是蓝色,一个是粉红色,另一个是橙色。当我单击每个UIButton时,我想直接从它的backgroundColor属性中获取准确的RGB(红、绿、蓝)颜色值。(例如,如果我单击带有粉红色backgroundColor的UIButton,我将获得返回的RGB值-R:255,G:0,B:128。)另一个解释这一点的方法是,我想将UIButton的UIColorbackgroundColor转换为UIColorRGB值。在Swift中,提取UIB

ios - 如何从 ActionSheet 更改 UIButton 的文本

我想更改UIButtoncity的文本。但是它不起作用,你能告诉我这里的问题是什么吗?这个IBActionsetUpCityDropDown连接到同一个UIButton。@IBActionfuncsetUpCityDropDown(){letActionSheet=UIAlertController(title:"WhichCity?",message:"CityName",preferredStyle:UIAlertControllerStyle.ActionSheet)letcancelActionButton:UIAlertAction=UIAlertAction(title:"

ios - 删除所选 UIButton 中的突出显示

一个普通的UIButton应该是这样的(我知道按钮应该与其他文本有不同的颜色,但这是一个特例):我想使用UIButton的selected属性来确定它是否应该是粗体,并且我已经将.Selected控件状态设置为粗体文本使用以下代码:letboldedOption=[NSFontAttributeName:UIFont.boldSystemFontOfSize(15),NSForegroundColorAttributeName:UIColor.whiteColor()]signInButton.setAttributedTitle(NSAttributedString(string:"

ios - Swift 2.2 中的 UIButton。如何添加不同的目标?

我在代码中创建了按钮。letitem=UIButton()item.setImage(UIImage(named:"Menu"),forState:.Normal)view.addSubview(item)如何添加来自其他VC的目标?我尝试了很多东西,但它没有编译。OtherClass的方法menuButtonAction()错误:item.addTarget(otherClassVar,action:#selector(OtherClass.menuButtonAction),forControlEvents:.TouchUpInside)item.addTarget(otherCl

ios - 如何向 UIButton 添加属性?

感谢所有帮助:)!使用iboutlet集合修复它并在viewDidLoad上添加属性我正在尝试向键盘键添加属性,例如layer.shadowColor或layer.shadowRadius。我得到一个错误'Valueoftype'(UIButton)'->()hasnomember'layer'如何解决这个问题?这是我的代码keyboardViewController.swift导入UIKit类KeyboardViewController:UIInputViewController{varnewKeyboardView:UIView!@IBActionfunckeyPressed(se