Tag: uibutton

在Scrolling Filmstrip中的每个UICollectionViewCell中调用UIButton

这是对我以前的一个后续问题,这次我在每个UICollectionViewCell中添加了UIButton的问题。 在深入研究这个问题之前,让我把目前所有的情况都介绍给大家。 以下是我的UICollectionView在UITableView中的Scrolling Filmstrip样式的工作原理的基本概要: 用一个自定义的UITableViewCell创build一个普通的UITableView 创build一个将被添加到单元格的contentView的自定义UIView 自定义UIView将包含一个UICollectionView 自定义UIView将成为UICollectionView的数据源和委托,并pipe理UICollectionView的stream布局 使用自定义UICollectionViewCell来处理收集视图数据 使用NSNotification通知主控制器的UITableView何时已经select一个集合视图单元并加载详细视图。 到目前为止,我已经能够在每个UICollectionViewCell中添加UIButton,并且当我点击UIButton时,它的图像将变成勾选标记,但是当我向上/向下滚动时会出现问题。 一旦带有选中标记UIButton的单元格离开屏幕并再次在屏幕上滚动,UIButton图像就开始混乱了。 例如,当单元格1中的UIButton图像应该被选中标记但不是。 相反,选中标记会出现在另一个单元格中。 下面是我的相关代码: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { PostsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PostsCollectionViewCell" forIndexPath:indexPath]; NSDictionary *cellData = [self.collectionData objectAtIndex:[indexPath row]]; cell.postTextLabel.text = [cellData objectForKey:@"text"]; cell.locationNameLabel.text = [cellData objectForKey:@"locationName"]; // >>> Select Button <<< UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom]; [selectButton setFrame:CGRectMake(110, 150, […]

UItableView用UIButton替代选中标记或用于多选的自定义CheckImage

我已经问了一个问题UItableView用UIButtonreplace复选标记 但到现在还没有解决的办法,谁都会提供我的解决scheme? 1.将此button设置为单元格可选,或者2.要更改默认选中标记与我的自定义图像 但function需要按照原样运行 提前致谢

我怎样才能得到不同的每个tableView行的UIButton状态?

在这个代码中,我有一个选定的状态和取消select状态为我的button。 当button被按下时,它变成绿色,再次按下它变成红色以表示取消select的状态。 然而,所有这一切都在一个DetailViewController,当我从我的tableView中select一个特定的行,然后单击button显示绿色,并返回并尝试不同的行,button显示绿色的另一行,这表示我已经按下它(我没有)。 我想知道是否有一种方法只显示绿色detailView我所select的行和红色的其他人? let defaults = UserDefaults.standard // Outlets @IBOutlet weak var goingButton: UIButton! // Actions @IBAction func goingButtonTapped(_ sender: UIButton) { goingButton.isSelected = !goingButton.isSelected if goingButton.isSelected == true { goingButton.setImage(UIImage(named: "goingSelected"), for: UIControlState.selected) defaults.set(true, forKey: "going") defaults.synchronize() defaults.bool(forKey: "going") print("defaults: \(defaults)") } else if goingButton.isSelected == false { goingButton.setImage(UIImage(named: "goingDeselected"), for: UIControlState.normal) defaults.set(false, […]

UIButton的图片位置取决于titleLabel的框架

我的问题很简单,但我找不到解决scheme。 我有一个标题和图像的UIButton。 无论发生什么事情,我都希望图像位置得到修复,所以我这样设置: [button setImageEdgeInsets:UIEdgeInsetsMake(0.f, 0.f, 0.f, IS_IPHONE ? 20.f : 60.f)]; 我没有为button的titleLabel设置任何位置。 接下来发生的事情是我为button设置了新的标题,标题标签缩小或展开以适应新的文本,令人惊讶的是它使图像移动,所以很明显,尽pipe应用了图像边缘插入,图像位置取决于标签的框架。 我看到两个可以使用的解决scheme: 1)使图像独立于标签的框架 2)为标签设置固定大小 但是我不知道如何实现它们。 你能给我一些build议,我该如何解决这个问题?

未选中时不能更改button颜色

我有很多自定义button,我想为选中的状态设置颜色,而不是选中。 这是我的直觉 override func drawRect(rect: CGRect) { print("status = \(self.selected)") if self.selected { self.titleLabel?.textColor = UIColor(red: 255.0, green: 255.0, blue: 255.0, alpha: 1.0) }else { self.titleLabel?.textColor = UIColor(red: 166.0, green: 142.0, blue: 83.0, alpha: 1.0) } let path = UIBezierPath() path.moveToPoint(CGPoint(x: self.bounds.minX, y: self.bounds.maxY)) path.addLineToPoint(CGPoint(x: self.bounds.maxX, y: self.bounds.maxY)) path.closePath() // path.addLineToPoint(center) UIColor.blackColor().setStroke() path.lineWidth = 3.0 […]

如何使用自动布局在代码中使用多行标签创build和添加UIButton?

有很多链接如何调整标签的大小,但是缺less如何根据标签大小调整UIButton大小的信息。 目前,我有自动布局设置屏幕视图(所有的系统约束是从IB添加),一切工作正常,但需要在屏幕底部添加dynamic内容。 我需要创build并随机添加随机数字的随机长度的标题。 所以,这里是创build和添加button的代码片段: // Loop UIButton *myButton = [UIButton new]; UIButton.frame = CGRectMake(0, previousButtonOriginY, self.view.bounds.size.width, 20); myButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; myButton.titleLabel.textAlignment = NSTextAlignmentLeft; myButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [myButton setTitle:@"very long title…" forState:UIControlStateNormal]; myButton.titleLabel.numberOfLines = 0; [self.footerView addSubview:myButton]; 问题是button的框架高度保持20px,但标签string显示在三行上,因此与另一个button标题重叠。 如果我添加[myButton sizeToFit],那么button的宽度就会resize以适合所有的文本到一行,所以标题超出了屏幕。 如果我添加[myButton sizeThatFits:CGSizeMake(320,100)],那么resize根本不起作用。 我知道sizeToFit不应该被称为所有,因为它不是自动布局的一部分,但是需要build议,如何轻松地使button适合其标签屏幕320宽度。 我觉得我需要从代码中添加系统约束,但之前没有这样做,所以不知道它应该如何。 我可能需要从代码中添加大量的约束才能使这个简单的事情工作:)

长按UIButton

我想知道如果我能抓住一个事件(通过通知或其他机制),一个UIButton如果有人按住UIButton键过长的时间; 比单button更长的时间 – 比方说按住button几秒钟的人… 谢谢。

按下button时如何切换标签的隐藏?

我想弄清楚如何只显示一个标签,而在操作系统按下button。 我知道如何操作触摸事件,但我不确定如何将UILongPressGestureRecognizer合并到此。

绘制backgroundcolor&边框与背景PNGs

我想为我的iPad应用程序的大多数button特定的RGBhex颜色。 我所做的是:我已经在我的项目中实现了UIButton子类,它模拟所需的背景颜色,文本颜色和button边框 – 然后我在我需要UIButton项目中随处使用它。 我的用户界面/用户体验devise师不提供PNG,他坚持我模仿相同颜色的网站button有hex代码。 我更多的是一个背景PNG的球迷。 现在,这个问题与编程的关系,你可能想知道的是,我正在访问.layer.borderWidth & .layer.borderColor属性,这个属性最终被无处不在使用。 那么,这种方法是否对应用程序有所帮​​助,而不是使用背景PNG? 注意 (如果相关) :所有button的大小相同。

如何在UIImageView的左上angular和右下angular创buildUIButton

我希望在imageview的左上angular和右下angular创build删除button。 但它看起来不像我所需要的。 我希望这两个button应该放在红色边框的angular落 要创buildbutton我使用下面的代码 UIImageView * tappedView = (UIImageView *)[recognizer view]; [tappedView.layer setBorderColor: [[UIColor redColor] CGColor]]; [tappedView.layer setBorderWidth: 2.0]; tappedView.layer.cornerRadius = 10; tappedView.layer.masksToBounds = NO; UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom]; deleteBtn.frame = CGRectMake(0, 0, 20, 20); [deleteBtn setImage:[UIImage imageNamed:@"close.png"]forState:UIControlStateNormal]; deleteBtn.layer.shadowColor = [[UIColor blackColor] CGColor]; deleteBtn.layer.shadowOffset = CGSizeMake(0,4); deleteBtn.layer.shadowOpacity = 0.3; [tappedView addSubview:deleteBtn]; [deleteBtn addTarget:self action:@selector(deleteProperties:) […]