我正在编写一个骰子应用程序。 如果我使用UIImage视图,我知道如何将图像更改为不同的骰子面。但是我想使用UIButton作为骰子,这样每次用户按下具有特定骰子面部图像的骰子按钮时,图像就会更新到另一个骰子图像。我知道如何使用arc4random随机更改图像,但我不知道如何在UIButton上应用相同的概念。
答案 0 :(得分:2)
对于Swift 4,答案应该是:
sender.setBackgroundImage(UIImage(named: "Button-Normal"), for: UIControl.State.normal)
答案 1 :(得分:0)
快速5
WITH RECURSIVE un_id AS (
SELECT id
FROM unit
WHERE id = :idParent -- or parentid if you want to exclude the parent itself
UNION
SELECT unit.id
FROM unit
JOIN un_id
ON unit.parentid = un_id.id
)
SELECT unl.name AS text,
un.id AS value,
(case
when cast((select count(*) from employee where employee.unit_id = un.id) as varchar(10)) != '0'
then cast(1 as Boolean)
else cast(0 as BOOLEAN) end) as disabled
,
cast(0 as varchar(10)) as favoriteNbr,
cast(null as varchar(10)) as favoriteId
FROM un_id -- reference to the CTE
JOIN unit un
USING (id)
LEFT OUTER JOIN unitlang unl ON unl.unit_id = un.id
Where unl.lang = :lang
order by app_order asc
答案 2 :(得分:-1)
@IBAction func myImageButton(_ sender: UIButton) {
sender.setImage(UIImage(named: "Button-Normal"), for: UIControlState.normal)
}