Tag: uibutton

具有圆angular和阴影的UIBarButtonItem

我想在UIBarButtonItem上有圆angular和阴影。 UIButton *useButton = [UIButton buttonWithType:UIButtonTypeCustom]; 然后,我尝试设置阴影和圆angular: useButton.layer.masksToBounds = NO; useButton.layer.cornerRadius = 4; useButton.layer.shadowOffset = CGSizeMake(0, 1.5); useButton.layer.shadowRadius = 0.5; useButton.layer.shadowOpacity = 1.0; useButton.layer.shadowColor = [BSTCMColorUtility colorFromHexString:@"#AFAFAF"].CGColor; 最后我做了UIBarButtonItem : UIBarButtonItem *useItem = [[UIBarButtonItem alloc] initWithCustomView:useButton]; [self.navigationItem setRightBarButtonItems:@[useItem]]; 我没有得到圆angular,但我确实得到了阴影。 如果我添加: useButton.clipsToBounds = YES; 和/或: useButton.layer.masksToBounds = YES; 我得到圆angular,但没有阴影。 所以我想我会尝试添加一个子图层。 CALayer *useButtonShadowLayer = [CALayer new]; useButtonShadowLayer.frame = […]

如何删除一个disbled UIButton灰色的外观

我有一个UIButton,当它处于禁用状态和正常状态时,我想看起来完全一样。 现在它有一个灰色的外观。

在Swift中添加一个string属性到UIButton

我怎样才能将一个string属性与一个UIButton在Swift中关联? 我不希望string显示为button文本,只是将其作为标识符或键分配给button。 这是我到目前为止: func createAnswerButtons() { var index:Int for index = 0; index < self.currentQuestion?.answers.count; index++ { // Create an answer button view var answer:AnswerButtonView = AnswerButtonView() selection.setTranslatesAutoresizingMaskIntoConstraints(false) // Place into content view self.scrollViewContentView.addSubview(answer) // Add a tapped gesture recognizer to the button let tapGesture:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("answerTapped:")) answer.addGestureRecognizer(tapGesture) // Add constraints etc […]

在选定的UIButton上单击时突出显示的UIButton状态

当我点击已经select的button时,我想让我的UIButton显示突出显示的状态。 基本上在突出显示的状态,我应用一个* .png图像作为我的UIButton backgroundImage给予按下的效果。 但是,如果button已经在选定的状态当我再次点击它,我只是看不到突出显示的状态,但它直接进入正常状态! 观看问题 – >问题的 video! 请帮助 //0 init UIButton UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y, aSide, aSide)]; //1 Give it a backgroundColor [button setBackgroundColor:aColor]; [..] //2 Set titleLabel and its style [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted]; UIImage *shadowImage = [UIImage imageNamed:kBtnShadow]; shadowImage = […]

UIButton背景颜色突出显示/select状态问题

我有一个UIButton ,我创build了一个扩展,为不同的状态添加背景颜色。 我使用下面的代码: extension UIButton { func setBackgroundColor(color: UIColor, forState: UIControlState) { UIGraphicsBeginImageContext(CGSize(width: 1, height: 1)) CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), color.CGColor) CGContextFillRect(UIGraphicsGetCurrentContext(), CGRect(x: 0, y: 0, width: 1, height: 1)) let colorImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() self.setBackgroundImage(colorImage, forState: forState) } } // Set Button Title and background color for different states self.donateButton.setBackgroundColor(UIColor.redColor(), forState: .Normal) self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Normal) self.donateButton.setBackgroundColor(UIColor.greenColor(), forState: […]

我怎样才能在界面生成器中添加子视图到UIButton

就像我说的,我在界面生成器中添加一个UIButton,我想添加一个UILabel,UIImageView作为button的子视图,但是我不能在它上面添加任何对象。 有人知道如何做到这一点? 非常感谢你。 我可以使用代码来实现,但我想在IB中实现,所以我可以在任何我想要的类中使用它。

如何创build一个循环UIButton?

一切都在标题! 我想创build一个纯粹的圆形UIButton。 到目前为止我所能做的最好的是一个圆angular的方形button… Thx

将UIButton的属性赋给SpriteKit中的SKSpriteNode

我想知道是否有一种方法来给一个UIButton的属性,例如一旦它被按下就变暗button,…给SKSpiteNode因为SKSpiteNode有更多的自定义,因为我使用的是SpriteKit 。 我见过其他1个这样的问题,但没有任何答案。 这里是我必须创buildSKSpriteNode和检测触摸它的代码: import SpriteKit class StartScene: SKScene { var startButton = SKSpriteNode() override func didMoveToView(view: SKView) { startButton = SKSpriteNode(imageNamed: "playButton") startButton.size = CGSize(width: 100, height: 100) startButton.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 – 50) self.addChild(startButton) } override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { /* Called when a […]

swift中tableView中按下了哪个单元格button?

我已经阅读了类似这样的问题,但这些代码没有为我工作,所以请帮助:我有一个表格视图与每个单元格中的一些button – 此表视图是用户的因素,我添加button到该tableview – 当用户有付钱的button隐藏在该单元格中的因素,在另一个单元格中的另一个因素,当用户没有支付薪酬的钱不隐藏 – 这就是我想要检测哪些单元格button按下? 我知道,在表视图中,我们可以检测到哪个单元格按下但是这是不同的,因为用户只要按下该单元格中的button不按下所有的单元格 由于我的代码太长,我只是把表视图代码在这里 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "factorCell", for: indexPath) as! FactorCell cell.factorTitle.text = factorTitle[indexPath.row] cell.factorCode.text = factorCodes[indexPath.row] cell.factorDate.text = factorDate[indexPath.row] cell.factorHour.text = factorHour[indexPath.row] cell.factorPrice.text = factorPrice[indexPath.row] cell.factorCondition.text = factorConditions[indexPath.row] cell.factorBill.tag = indexPath.row cell.factorBill.addTarget(self,action:#selector(factorViewController.Bill), for: UIControlEvents.touchUpInside) cell.factorDetail.tag = […]

迅速ios键盘扩展 – 长按/按住

我需要知道如何添加长按(按住)function到ios自定义键盘扩展,以便我con显示多个键来select一个。 预期的devise 我的项目结构 当前的按键动作代码 – 代码可以将button的标题添加为任何代理文本字段作为新的文本。 @IBAction func keypress(sender: UIButton!){ let typedCharacter = sender.titleLabel?.text let proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText(typedCharacter!) } func loadKeyboard(){ let keyboardNib = UINib(nibName: "View", bundle: nil) keyboardView = keyboardNib.instantiateWithOwner(self, options: nil)[0] as! UIView view.backgroundColor = keyboardView.backgroundColor view.addSubview(keyboardView) } 希望看到build议和完整的答案