Tag: uibutton

自动布局UIButtons之间相等的空间

我是新的自动布局,所以在这里阅读有点问题堆栈我试图alignment我的5个UIButtons在单元格的底部有相等的空间(例如7点),我试着使用代码,它doesn'工作。 我的问题是 – 我怎样才能使用Interface Builder? UIButton *button1 = self.btnFavorite, *button2 = self.btnCalendar, *button3 = self.btnEmail, *button4 = self.btnMessage, *button5 = self.btnCall; NSMutableArray *constraintsForButtons = [[NSMutableArray alloc] init]; float unusedHorizontalSpace = self.bounds.size.width – button1.intrinsicContentSize.width – button2.intrinsicContentSize.width – button3.intrinsicContentSize.width – button4.intrinsicContentSize.width – button5.intrinsicContentSize.width; NSNumber *spaceBetweenEachButton = [NSNumber numberWithFloat: unusedHorizontalSpace / 5 ] ; [constraintsForButtons addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(space)-[button1]-(space)-[button2]-(space)-[button3]-(space)-[button4]-(space)-[button5]-(space)-|" […]

哪个更好,setEnabled或setUserInteractionEnabled?

我想对用户触摸进行UIButton禁用。 setEnabled和setUserInteractionEnabled都可以做到这一点。 哪个更好? 他们有什么不同?

为UIButton添加目标 – iOS

任何人都可以帮助我如何添加操作来调用下面的方法使用UIButton 。 -(void)navigatePics:(id)sender andIndex:(NSInteger *)index{}

Swift:以UICollectionViewCell中的IndexPath中的多个UIButton以编程方式,nextTarget不会单击

我以编程方式在UICollectionViewCell的indexPath中创build了多个UIButton。 现在我想要打印“点击添加到collections夹”,但点击UIButton后,它不打印任何东西。 UIButton不会查看除addTarget函数之外的所有内容,而不是单击。 import UIKit //**UICollectionViewCell** class DescriptionCell: UICollectionViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { override init(frame: CGRect) { super.init(frame: frame) setupCell() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } lazy var addToCart: UIButton = { let btn = UIButton() btn.setTitle("Add to favourite", for: .normal) btn.isUserInteractionEnabled = true btn.setTitleColor(.white, for: .normal) btn.backgroundColor = […]

iOS:多个button的自动布局

在我的应用程序,我有这样的4英寸的屏幕视图: 然后,当应用程序在3.5英寸屏幕的iPhone上运行时,我想缩小button的大小,所以我按照以下方式设置我的布局: 但最后我以这种方式获得了一个观点 这样,我的button的大小是确定的,但他们没有alignment,所以在这种情况下,有什么办法alignmentbutton? 谢谢

在Button上单击更改viewController

我是iPhone编程新手。 我正在尝试的是我有一个button的屏幕。 我想改变视图控制器不仅是视图,当我点击该button(我知道如何添加子视图),因为从第二个视图控制器,我必须去第三个视图是不可能的,如果我在第一个子视图地点。 有人可以帮我吗? 这可能吗? 如果是的话,怎么样? 所有的视图和视图控制器都是编程创build的。 我没有使用IB。 编辑:这里是点击button时触发的相关代码 -(id)showCurrentLoc:(id)sender { locationController = [currentLocController alloc]; [entry removeFromSuperview]; [newLoc removeFromSuperview]; [currentLoc removeFromSuperview]; [self.view setBackgroundColor:[UIColor clearColor]]; //[self.view addSubview: [locationController view]]; [self.navigationController pushViewController:locationController animated:YES]; [locationController release]; return 0; } //Location Controller is the tableViewController 谢谢维克

添加一个子视图到UIButton

我试图添加一个customBadge作为UIButton的子视图 – 这是我的代码到目前为止 – //msg count initiaition //CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2"]; CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2" withStringColor:[UIColor whiteColor] withInsetColor:[UIColor redColor] withBadgeFrame:YES withBadgeFrameColor:[UIColor redColor] withScale:2.0 withShining:YES]; // Set Position of Badge 1 [customBadge1 setFrame:CGRectMake(self.view.frame.size.width/2-customBadge1.frame.size.width/2+_MsgHeadBtn.frame.size.width/2, 110, customBadge1.frame.size.width, customBadge1.frame.size.height)]; //add badge to view [_MsgHeadBtn addSubview:customBadge1]; 我试图添加子视图的button是_MsgHeadBtn,这是下面截图顶部LH的电子邮件图标。 我试图让自定义徽章在电子邮件图标的右侧显示轻微,但最终会在截图中显示结果! 任何人都可以提供任何意见,我要去哪里错了!

裁剪UIButton标题

我正在使用UIButton的标题的自定义字体。 它的作品,除了这个特定的字体,第一个字符的一部分被剪辑。 例如: 我尝试设置contentEdgeInsets和titleEdgeInsets,似乎无法得到它不剪裁。 我也尝试将button.titleLabel.clipsToBounds属性设置为NO; 任何build议将不胜感激。

如何定义哪个button被按下,如果他们都有相同的IBAction?

我有两个UIButtons(我创build它们使用IB),它连接到文件的所有者与相同的IBAction,我怎样才能定义他们被按下?

以编程方式中心UIButton

我有一个UIButton,我以编程方式添加。 这里没有问题,它应该像它应该和看起来不错。 然而,当我倾斜手机风景的button不正确,我希望它仍然居中。 肖像: 景观: 我已经尝试了一堆东西,但似乎无法得到它的工作,在我看来,autoresizing应该照顾它,但是…它不起作用的情况下。 – (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 49)]; _notMeButton = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *butImage = [[UIImage imageNamed:@"notme.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:6]; UIImage *butImagePressed = [[UIImage imageNamed:@"KC_notmePressed.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:6]; [_notMeButton setBackgroundImage:butImage forState:UIControlStateNormal]; [_notMeButton setBackgroundImage:butImagePressed forState:UIControlStateHighlighted]; [_notMeButton setTitle:NSLocalizedString(@"Change address", @"KlarnaCheckout") forState:UIControlStateNormal]; [_notMeButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; [_notMeButton setTitleColor:[UIColor […]