Muh*_*waz 5
您可以使用以下方法为您的 UIButtons 分配标签并在 UIButton 操作上通过管理对象将您的图像添加到数组的特定索引上
例如
var selectedIndex or selectedTag // of your UIButton
在按钮上单击更新您的 selectedIndex 值
self.selectedIndex = sender.tag
然后在您的didFinishPicking方法中使用 selectedIndex 上的选定图像更新您的图像数组,并使用以下方式更新您的按钮图像
images.insert(yourSelectedImage, at: selectedIndex)
self.setImagesForButtons()
现在使用 UIButton Outlet 将您选择的图像分配给 UIButton 例如,您的五个按钮有五个插座
@IBOutlet weak var yourButtonOutlet1: UIButton!
@IBOutlet weak var yourButtonOutlet2: UIButton!
@IBOutlet weak var yourButtonOutlet3: UIButton!
@IBOutlet weak var yourButtonOutlet4: UIButton!
@IBOutlet weak var yourButtonOutlet5: UIButton!
func setImagesForButtons()
{
if (self.selectedIndex == 0)
{
if (images[selectedIndex] != nil)
{
self.yourButtonOutlet1.setImage(images[selectedIndex], for: .normal)
}
else
{
// set plus icon image to your button
}
}
else if (self.selectedIndex == 1)
{
if (images[selectedIndex] != nil)
{
self.yourButtonOutlet2.setImage(images[selectedIndex], for: .normal)
}
else
{
// set plus icon image to your button
}
}
else if (self.selectedIndex == 2)
{
if (images[selectedIndex] != nil)
{
self.yourButtonOutlet3.setImage(images[selectedIndex], for: .normal)
}
else
{
// set plus icon image to your button
}
}
else if (self.selectedIndex == 3)
{
if (images[selectedIndex] != nil)
{
self.yourButtonOutlet4.setImage(images[selectedIndex], for: .normal)
}
else
{
// set plus icon image to your button
}
}
else if (self.selectedIndex == 4)
{
if (images[selectedIndex] != nil)
{
self.yourButtonOutlet5.setImage(images[selectedIndex], for: .normal)
}
else
{
// set plus icon image to your button
}
}
}
更多推荐
如何用,图像,照片,用户
发布评论