I\'m using a vertical UIButton in a portrait app (Just a normal button that is of width 60 and Height 160)
I want to put the label Vetically down the button instead of a
I add the same problem, for buttons in stack view So I needed something dynamic
for Swift 4.2
class VerticalButton: UIButton {
override func titleRect(forContentRect bounds: CGRect) -> CGRect {
var frame: CGRect = super.titleRect(forContentRect: bounds)
frame.origin.y = 0
frame.size.height = bounds.size.height
return frame
}
}
extension UILabel {
@IBInspectable
var rotation: Int {
get {
return 0
} set {
let radians = CGFloat(CGFloat(Double.pi) * CGFloat(newValue) / CGFloat(180.0))
self.transform = CGAffineTransform(rotationAngle: radians)
}
}
}
and
let button = VerticalButton.init(type: UIButton.ButtonType.custom)
button.titleLabel?.textAlignment = .center
button.titleLabel?.rotation = -90