ios - Swift: rotate oblique a button in iOS8? -
let's have 1 or more 100*50 rectangular buttons on viewcontroller.
import uikit class viewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } @ibaction func mybutton(sender: uibutton) { } }
usually put graphic images image. apply auto layout.
but! need them oblique not horizontal, i.e. if have square, need rotate diamond (45°), it's same. know it's not possible via interface builder. how make code?
maybe should use cgaffinetransformrotate or rotatetranform don't know how start
the best way rotate views layer, cgaffinetransformmaketranslation indicates point in layer layer rotate around, remember layers go (0,0) (1.1) middle (0.5, 0.5):
var transform = cgaffinetransformmaketranslation(0.5, 0.5) var angle = cgfloat(m_pi / 2.0) //90 degress rotation transform = cgaffinetransformrotate(transform, angle) button.transform = transform button.layer.rasterizationscale = uiscreen.mainscreen().scale button.layer.shouldrasterize = true button.setneedsdisplay()
Comments
Post a Comment