UILabelnの枠線が消せずに困っています。
直接UILabelの枠線を消す方法ではなかったのですが、下記の記事をみて枠線を消すコードを真似しました。
UISearchBarの枠線を消すには?
lang
1 tempoLbl = UILabel(frame: CGRect(x: 0, y: 0, width: self.view.frame.width/2, height: self.view.frame.height/10)) 2 tempoLbl.text = String(Int(stepVal)) 3 tempoLbl.textColor = UIColor(red: 0.1, green: 0.1, blue: 1.0, alpha: 1.0) 4 tempoLbl.textAlignment = NSTextAlignment.center 5 tempoLbl.font = UIFont.systemFont(ofSize: 72) 6 tempoLbl.backgroundColor = UIColor.white 7 tempoLbl.layer.position = CGPoint(x: self.view.frame.width/4, y: self.view.frame.height/8) 8 //これで枠線を消せるはず? 9 tempoLbl.layer.borderColor = UIColor.white.cgColor 10 tempoLbl.layer.borderWidth = 1.0 11 12 self.view.addSubview(tempoLbl)
上記がUILabelを作っている部分のコードです。
lang
1 tempoLbl.layer.borderColor = UIColor.white.cgColor 2 tempoLbl.layer.borderWidth = 1.0 3
この2行で枠線を指定ができるようで、これで消せると思ったのですが消せずにいます。
layer.positionで位置を変えているのは何か理由があるのでしょうか?
UILabelは設定しなければ枠線付かない気がします。。。 https://i-app-tec.com/ios/label.html
いつもの癖でpositionで指定してしまっていました。UILabelを宣言した際のxとyにpositionで移動していた値を入れるとずれてしまうのすが本来どう指定するのが良いのでしょうか
設定はしてないと思うのですがやはりコードのどこかで指定してしまっているのでしょうか
ちょっと原因は分からないんですけど、layer.positionのせいでゴミ(?)が出ているようです。framで座標設定してみて下さい。(layer.borderColorとlayer.borderWidthも不要です)
回答1件
あなたの回答
tips
プレビュー