練習でおみくじを作っているのですが、
結果によって大きさ、色を指定しつつ、カスタムフォントを使いたいです。
大きさ、色を指定するというところまでは至ったのですが、それをコード内で設定するとラベルのユーティリティエリアでカスタムフォントを指定しても変更されません。
コード内でカスタムフォントを指定することは可能でしょうか?
import UIKit class NextViewController: UIViewController { @IBOutlet weak var resultLabel: UILabel! @IBOutlet weak var imageView: UIImageView! var image1: UIImage! var image2: UIImage! var image3: UIImage! var image4: UIImage! var image5: UIImage! override func viewDidLoad() { imageView.layer.cornerRadius = 37.0 imageView.layer.masksToBounds = true super.viewDidLoad() image1 = UIImage(named:"MSkun.png") image2 = UIImage(named:"cho2.png") image3 = UIImage(named:"cho3.png") image4 = UIImage(named:"cho4.png") image5 = UIImage(named:"cho5.png") } @IBAction func tapped(sender: AnyObject) { let randNum = Int(arc4random_uniform(6)) if randNum == 0 { imageView.image = image1 resultLabel.text = "大吉!!" resultLabel.textColor = UIColor.red resultLabel.font = UIFont.systemFont(ofSize: 60); }else if(randNum == 1){imageView.image = image5 resultLabel.text = "中吉" resultLabel.textColor = UIColor.orange resultLabel.font = UIFont.systemFont(ofSize: 50); }else if(randNum == 2){imageView.image = image3 resultLabel.text = "吉" resultLabel.textColor = UIColor.yellow resultLabel.font = UIFont.systemFont(ofSize: 40); }else if(randNum == 3){imageView.image = image4 resultLabel.text = "小吉" resultLabel.textColor = UIColor.green resultLabel.font = UIFont.systemFont(ofSize: 30); }else if(randNum == 4){imageView.image = image2 resultLabel.text = "末吉" resultLabel.textColor = UIColor.blue resultLabel.font = UIFont.systemFont(ofSize: 25); } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/20 02:59