Created
January 21, 2016 15:35
-
-
Save tdtsh/c10b442dc32499a3d60d to your computer and use it in GitHub Desktop.
Swift2 ボタンにラベルをのせ、NSLineBreakModeを指定
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 画面になにか重ねて表示する | |
func renderView() { | |
/** | |
* ボタン | |
*/ | |
let buttonTake = UIButton(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width - 50, height: 50)) | |
buttonTake.backgroundColor = UIColor.init(colorLiteralRed: 0.3, green: 0.3, blue: 0.7, alpha: 0.5) | |
buttonTake.layer.cornerRadius = 5.0 | |
buttonTake.layer.masksToBounds = true | |
buttonTake.setTitle("", forState: UIControlState.Normal) | |
buttonTake.layer.position = CGPoint(x: self.view.bounds.width/2, y:self.view.bounds.height - 55) | |
buttonTake.addTarget(self, action: "takePhoto:", forControlEvents: .TouchUpInside) | |
self.view.addSubview(buttonTake) | |
/** | |
* ボタンの中のラベル | |
*/ | |
let labelForButton = UILabel.init(frame: CGRect.init(x: 0, y: 0, width: buttonTake.frame.size.width, height: buttonTake.frame.size.height)) | |
labelForButton.lineBreakMode = NSLineBreakMode.ByTruncatingHead | |
// ByWordWrapping 単語の境界で折り返す。 | |
// ByCharWrapping 文字で折り返す。 | |
// ByClipping 折り返さず、端を超えた文字は表示されない。 | |
// ByTruncatingHead 文字列末尾が表示され、行の先頭に三点リーダ | |
// ByTruncatingTail 文字列先頭が表示され、行の末尾に三点リーダ | |
// ByTruncatingMiddle 文字列先頭と末尾が表示され、中央に三点リーダ | |
labelForButton.numberOfLines = 1 | |
labelForButton.text = "画面をタップすると写真撮影をして、写真をアルバムに保存します" | |
labelForButton.textColor = UIColor.whiteColor() | |
labelForButton.font = UIFont.init(name: "Helvetica-Bold", size: 13.0) | |
labelForButton.textAlignment = NSTextAlignment.Center | |
buttonTake.addSubview(labelForButton) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment