Tag: uibutton

Swift将多个图像添加到单个UIButton

在我的应用程序中,我想在一个UIButton上添加多个图像。 这是我现在所拥有的: NextButton = UIButton(frame: CGRect(x: width*0, y: height*0.55, width: width*0.95, height: height*0.05)) NextButton.addTarget(self, action: #selector(OnNextPressed), for: .touchUpInside) NextButton.isExclusiveTouch = true NextButton.setTitle("ButtonText", for: UIControlState()) NextButton.setTitleColor(UIColor(red:0, green:0, blue:0, alpha:1.0), for: UIControlState()) NextButton.setBackgroundImage(UIImage(named: "ButtonOutline"), for: .normal) view.addSubview(NextButton) 我想第二个图像作为箭头指向下一页。 提前致谢 :) button的其余部分工作,但我不知道如何使箭头出现

如何使用渐变UIButton创build光面

创build一个像这样的button最简单的方法是什么,而不必使用.png并将其设置为背景?

按下button后,标题消失

我正在尝试创build一个像这样的push-on-push-off-likebutton,虽然我的代码有点不同: UIButton* alertsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; alertsButton.frame = CGRectMake(170, 43.5, 130, 130); [alertsButton.titleLabel setFont:[UIFont fontWithName:@"Novecento wide" size:22]]; [alertsButton setTitle:NSLocalizedString(@"Alerts", nil) forState:UIControlStateHighlighted]; [alertsButton setTitle:NSLocalizedString(@"Alerts", nil) forState:UIControlStateNormal]; [alertsButton setTitle:NSLocalizedString(@"Alerts", nil) forState:UIControlStateSelected]; [alertsButton addTarget:self action:@selector(toggleAlerts:)forControlEvents:UIControlEventTouchUpInside]; -(void)toggleAlerts:(id)sender { UIButton *button = (UIButton *)sender; if (button.selected) { button.selected = NO; [button setImage:[UIImage imageNamed:@"off.png"] forState:UIControlStateNormal]; [button.titleLabel setFont:[UIFont fontWithName:@"Novecento wide" size:22]]; NSLog(button.titleLabel.text); […]

修改标题标签的UIButton似乎改变了它的框架

有些奇怪的事情正在发生。 基本上,我正在尝试重新创build消息应用程序。 所以当我试图让用户input至less1个字符时发送button从灰色更改为蓝色。 问题来了,当我试图改变titleLabel,button将消失。 后来我发现它恢复到原来的位置(当键盘没有显示)。 为什么这样做? 如果我不修改标题标签,一切照旧。 但是,如果我这样做,UIButton会回到原来的位置。 如果你需要任何示例代码让我知道,但我不知道该把什么,因为它只是[self.button.titleLabel setTextColor: [UIColor blueColor]; 在UITextViewdidChange但它的行为奇怪。 谢谢! 艾伦

UIButton隐藏在UIToolbar后面

上下文 我有一个UIButton,我添加,方法如下: [self.view addSubview:[self returnCustomSubmitButton]]; 我不添加工具栏作为子视图,我将ViewControllers导航控制器属性toolBarHidden设置为NO。 – [self.navigationController setToolbarHidden:NO animated:NO]; 在视图将apear 额外的细节 我这样做的原因是因为我想创build类似于工具栏(注意:这是一个UITabBar,但我正在寻找相同的形状)的东西 – 所以我添加一个工具栏,然后添加一个UIButton viewControllers视图并使用工具栏坐标来定位UIButton 我试图遵循这一点(注:这又是一个UITabBar),但挣扎: http : //idevrecipes.com/2010/12/16/raised-center-tab-bar-button/ 问题 UIButton隐藏在UIToolbar中(我想让它坐在工具栏的顶部)。 问题 我如何解决这个问题? 将UIButton转换成UIBarButtItem是否更好? 并添加一个UIButton到viewController的toolbarItems数组? 我将如何做到这一点? 更新 经过大量的尝试来解决这个问题,这是我使用UINavigationController和事实,我添加一个UIButton到“自定义内容”区域和导航工具栏坐在顶部,无论我做。 见下文:

如何在表格视图中一次select单选button

我在表视图单元格中有一个单选button。 这是我的单选button -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCell"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; UIButton *newRadioButton = [UIButton buttonWithType:UIButtonTypeCustom]; newRadioButton.frame = CGRectMake(30, 0, 15, 14.5); [newRadioButton setImage:[UIImage imageNamed:@"unselect"] forState:UIControlStateNormal]; [newRadioButton setImage:[UIImage imageNamed:@"select"] forState:UIControlStateSelected]; cell.accessoryView = newRadioButton; if ([indexPath isEqual:selectedIndex]) { newRadioButton.selected = YES; […]

UITableViewCellbutton标签在UISearchController中返回所需的IndexPath,而不是FetchedResultsController

我在Swift 2.0的Core Data项目的UITableView上实现了NSFetchedResultsController 。 另外,我有一个UISearchController实现。 除了我在自定义的UITableViewCellbutton上遇到的行为之外,一切都可以正常工作。 当UISearchController处于活动状态时, customTableViewCell的button按照它们应该的方式工作。 如果在fetchedResultsController显示其结果时单击相同的button,则方法认为索引0是发件人,无论我单击哪个button。 func playMP3File(sender: AnyObject) { if resultsSearchController.active { // ** THIS WORKS ** // get a hold of my song // (self.filteredSounds is an Array) let soundToPlay = self.filteredSounds[sender.tag] // grab an attribute let soundFilename = soundToPlay.soundFilename as String // feed the attribute to an initializer of […]

禁用具有特定标记的UIButton

我想禁用一个特定标签的button,我试试这个代码: UIButton *button = (UIButton *)[self.view viewWithTag:33]; [button setEnabled:FALSE]; 但它不工作,为什么?

自定义,无图像的UIButton标题消失

我在XIB中创build了一个没有图像的自定义UIButton。 当button被点击时,标题消失。 这些答案没有帮助我,因为我没有任何可以重叠文本的图像 按下button后,标题消失 iOS – 界面生成器:设置图像时,UIButton标题消失 具有自定义背景的UIButton会丢失标题 这也没有帮助,因为我没有任何背景颜色 UIButton标题消失 这一个也没有帮助 每次按下button都会改变标题

UIButton标题和图像的不同alignment方式

您好,我正在创build显示图像和标题的UIButton在同一时间。 我想标题和图像都居中,button要在图像上方。 问题是由于从button的string的本地化,string长度正在改变,从UIStoryboard结合边缘插入alignment不工作,因为我希望它的工作。 有人可以帮助我,并指出我在正确的方向吗?