LoginSignup
0
0

More than 5 years have passed since last update.

コピペで完成UILabel Swift3用

Posted at

使用したのは追記していきます。

Swift3

基本

let label: UILabel = UILabel()
label.backgroundColor = UIColor.orange
label.text = "テキスト"
label.font = UIFont(name: "HiraKakuProN-W6", size: 8.5)
label1.textColor = UIColor.white
self.addSubview(label1)

その他

//文字寄せ
label.textAlignment = NSTextAlignment.right
label.textAlignment = NSTextAlignment.center

//角を丸くする
self.imageView.layer.masksToBounds = true //マスク設定
label.layer.cornerRadius = 1.0


//背景を画像に
label.backgroundColor = UIColor(patternImage: UIImage(named: "hogeImg")!)

objc

//背景を画像に
label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blah"]];



UILabelを使って何か調べる

//UILabelの行数を調べる
NSInteger lineCount = 0;
CGSize textSize = CGSizeMake(cell.replyBody.frame.size.width, MAXFLOAT);
long rHeight = lroundf([cell.replyBody sizeThatFits:textSize].height);
long charSize = lroundf(cell.replyBody.font.leading); //ここはフォントによって微妙に変更する必要がある場合あり
lineCount = rHeight/charSize;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0