ios - IBDesignable View Rendering times out -
ios - IBDesignable View Rendering times out -
i've been working on app on , off few months starting first xcode 6/ios 8 beta release. 1 of favorite features added live rendering, made possible @ibdesignable
tag in swift.
i haven't been able single thing live render. figured must have been because beta release, decided wait total release come out seek again. still failed. figured there might artifacts beta releases in code, scrapped , started fresh. still doesn't work. granted, errors more descriptive now.
here code:
import uikit @ibdesignable class mybutton : uibutton { allow unpressed_color = uicolor(red: 221.0/256.0, green: 249.0/256.0, blue: 14.0/256.0, alpha: 1.0) allow pressed_color = uicolor(red: 166.0/256.0, green: 187.0/156.0, blue: 11.0/256.0, alpha: 1.0) var buttoncolorvalue: uicolor allow text_color = uicolor(red: 72.0/256.0, green: 160.0/256.0, blue: 5.0/256.0, alpha: 1.0) required init(coder: nscoder) { self.buttoncolorvalue = unpressed_color super.init(coder: coder) // initialization code self.settitlecolor(text_color, forstate: uicontrolstate.normal) self.settitlecolor(text_color, forstate: uicontrolstate.highlighted) self.settitlecolor(text_color, forstate: uicontrolstate.selected) } override func touchesbegan(touches: nsset, withevent event: uievent) { super.touchesbegan(touches, withevent: event) buttoncolorvalue = pressed_color self.setneedsdisplay() } override func touchesended(touches: nsset, withevent event: uievent) { super.touchesended(touches, withevent: event) buttoncolorvalue = unpressed_color self.setneedsdisplay() } override func touchescancelled(touches: nsset!, withevent event: uievent!) { super.touchescancelled(touches, withevent: event) buttoncolorvalue = unpressed_color self.setneedsdisplay() } override func drawrect(rect: cgrect) { buttoncolorvalue.setfill() allow ctx = uigraphicsgetcurrentcontext() cgcontextfillrect(ctx, rect) //uibezierpath(roundedrect: rect, cornerradius: 5.0).fill() } }
here errors when seek build 1 of these buttons in storyboard:
ib designables: failed update auto layout status: interface builder cocoa touch tool crashed ib designables: failed render instance of mybutton: rendering view took longer 200 ms. drawing code may suffer slow performance.
as can see in code, wanted button rounded. figured might reason problem, though surprised me apple design rounded rectangle drawing algorithm inefficient. switched setting color , drawing rectangle as-is. still had problems.
i figure (i hope, anyway) there 1 little thing i'm doing wrong, because i've googled , there no 1 else seems have problem. seems might kind of infinite loop?
it's not that's necessary me continue, getting live rendering work create development lot faster , easier me, because able see interfaces , test them without having run them.
thanks in advance has remote clue on how solve this.
apparently needed override init(frame: cgrect)
along init(code: nscoder)
.
got working! if care explain why wasn't working, great. otherwise, i'm fine here.
ios xcode rendering ibdesignable
Comments
Post a Comment