增加UIImageView高度的最简单方法?
问题描述:
我有3个图像在main.storyboard中响应我的UIImageView,我只想让我的图像中的一个(image.image = UIImage(named:"InnieBulb")
)增加到一个高度(可能是10%{298x330}),而其余2个保持不变。什么是最简单的方法来做到这一点?预先感谢您帮助我。增加UIImageView高度的最简单方法?
import UIKit
class CorrectController: UIViewController {
@IBOutlet var label1: UILabel!
@IBOutlet var scorelabel: UILabel!
@IBOutlet var button1: UIButton!
@IBOutlet var image: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.button1.layer.cornerRadius = CGFloat(Float(5.0));
button1.titleLabel?.textAlignment = NSTextAlignment.center;
let returnValue: Int = UserDefaults.standard.integer(forKey: "userScore")
scorelabel.text = "Your Score: \(returnValue)/11"
if (1...3 ~= returnValue) {
if (returnValue == 1)
{
label1.text = "Fin-tastic !"
button1.setTitle("Let's bubble on", for: .normal)
}
else if (returnValue == 2)
{
label1.text = "You're Fun !"
button1.setTitle("Bubbly Bloop", for: .normal)
}
else if (returnValue == 3)
{
label1.text = "You're Great !"
button1.setTitle("Let's Drift On", for: .normal)
}
image.image = UIImage(named:"InnieBubbles")
}
else if (4...6 ~= returnValue) {
if (returnValue == 4)
{
label1.text = "You're Sexy !"
button1.setTitle("Let's Swim On", for: .normal)
}
else if (returnValue == 5)
{
label1.text = "You're Fabulous !"
button1.setTitle("Let's Angle On", for: .normal)
}
else if (returnValue == 6)
{
label1.text = "You're Creative !"
button1.setTitle("Let's Moove On", for: .normal)
}
image.image = UIImage(named:"InnieBulb")
}
else if (7...10 ~= returnValue) {
if (returnValue == 7)
{
label1.text = "You're a Genius !"
button1.setTitle("Let's Trail On", for: .normal)
}
else if (returnValue == 8)
{
label1.text = "You're a Thinker !"
button1.setTitle("Let's Hook On", for: .normal)
}
else if (returnValue == 9)
{
label1.text = "Blimey !"
button1.setTitle("Bloop Bloop", for: .normal)
}
else if (returnValue == 10)
{
label1.text = "You're Bursting with Solutions !"
button1.setTitle("Innie, Here We Come!", for: .normal)
}
image.image = UIImage(named:"InnieKOI")
}
}
答
线后
image.image = UIImage(named:"InnieBubbles")
加入
image.frame.size.height = //your new height here
例如
image.frame.size.height = image.frame.height * 1.1
image.frame.height
返回一个只能得到的值。而image.frame.size.height
是可编辑的。
答
在的viewDidLoad()
结束时,写这些行:
if image.image == UIImage(named: "InnieBulb"){
var frame = image.frame
frame.size.height+=10
image.frame = frame
}