2016-05-07 3 views
0

このボックスのようなビューまたはテキストビューを作成したいと思います。 私はすでにnsattributedtextとしてdiv要素でHTMLを作成しようが、私は、段落すぐに段落の囲みを描画する

<div style='background-color:#4fa5d5; color:white; font-weight: bold'>title</div><div style='border: 5px solid black;'><p style='margin-left: 5px'>content</p></div>

任意の提案のための境界線を設定することはできませんか?

I want to make a view like this image

+0

編集可能ですか? – marosoaie

+0

いいえ..ただ読んでほしいだけのテキスト – cana

+0

あなたはwebviewを使用していますか?ネイティブビューを使用してこれを構築したくないですか? – marosoaie

答えて

1

私は、ユーザーインターフェイスの2 UILabels、他の上にものを作成示唆しています。それらの位置に制約する。 、下のラベル

bottomLabel.roundCorners(UIRectCorner.BottomLeft, radius: 10) 
bottomLabel.roundCorners(UIRectCorner.BottomRight, radius: 10) 

最後の一番下の角を丸める次にトップラベル

topLabel.roundCorners(UIRectCorner.TopLeft, radius: 10) 
topLabel.roundCorners(UIRectCorner.TopRight, radius: 10) 

の上部の角を丸める次に

extension UILabel { 
    func roundCorners(corners: UIRectCorner, radius: CGFloat) { 
     var bounds: CGRect = self.bounds 
     var maskPath: UIBezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius)) 
     var maskLayer: CAShapeLayer = CAShapeLayer() 
     maskLayer.frame = bounds 
     maskLayer.path = maskPath.CGPath 
     self.layer.mask = maskLayer 
     var frameLayer: CAShapeLayer = CAShapeLayer() 
     frameLayer.frame = bounds 
     frameLayer.path = maskPath.CGPath 
     frameLayer.strokeColor = UIColor.redColor().CGColor 
     frameLayer.fillColor = nil 
     self.layer.addSublayer(frameLayer) 
    } 
} 

境界線を追加します。そして、この拡張機能を追加します。

for label in [topLabel, bottomLabel] { 
    label.layer.borderColor = UIColor.blueColor.CGColor 
    label.layer.borderWidth = 1 
} 
+0

提案をいただきありがとうございます。 私はちょうどtextViewを使用していますので、選択可能です:) – cana

+0

@canaそれはあなたのために働きますか? – penatheboss

関連する問題