i'm trying make actionsheet shows in messages app on ios when try attach image in screenshot.
i realized in new uialertcontroller, can't fit custom views. way can make this?
my code looks pretty standard.
let alertcontroller = uialertcontroller(title: "my alertcontroller", message: "tryna show images here man", preferredstyle: uialertcontrollerstyle.actionsheet) let okaction = uialertaction(title: "oks", style: .default) { (action: uialertaction) -> void in alertcontroller.dismissviewcontrolleranimated(true, completion: nil) } let cancelaction = uialertaction(title: "screw it!", style: .cancel) { (action: uialertaction) -> void in alertcontroller.dismissviewcontrolleranimated(true, completion: nil) } alertcontroller.addaction(okaction) alertcontroller.addaction(cancelaction) self.presentviewcontroller(alertcontroller, animated: true, completion: nil)
uialertcontroller extends uiviewcontroller, has view property. can add subviews view heart's desire. trouble sizing alert controller properly. this, break next time apple adjusts design of uialertcontroller.
swift 3
let alertcontroller = uialertcontroller(title: "\n\n\n\n\n\n", message: nil, preferredstyle: uialertcontrollerstyle.actionsheet) let margin:cgfloat = 10.0 let rect = cgrect(x: margin, y: margin, width: alertcontroller.view.bounds.size.width - margin * 4.0, height: 120) let customview = uiview(frame: rect) customview.backgroundcolor = .green alertcontroller.view.addsubview(customview) let somethingaction = uialertaction(title: "something", style: .default, handler: {(alert: uialertaction!) in print("something")}) let cancelaction = uialertaction(title: "cancel", style: .cancel, handler: {(alert: uialertaction!) in print("cancel")}) alertcontroller.addaction(somethingaction) alertcontroller.addaction(cancelaction) dispatchqueue.main.async { self.present(alertcontroller, animated: true, completion:{}) }
swift
let alertcontroller = uialertcontroller(title: "\n\n\n\n\n\n", message: nil, preferredstyle: uialertcontrollerstyle.actionsheet) let margin:cgfloat = 10.0 let rect = cgrect(x: margin, y: margin, width: alertcontroller.view.bounds.size.width - margin * 4.0, height: 120) let customview = uiview(frame: rect) customview.backgroundcolor = .green alertcontroller.view.addsubview(customview) let somethingaction = uialertaction(title: "something", style: .default, handler: {(alert: uialertaction!) in print("something")}) let cancelaction = uialertaction(title: "cancel", style: .cancel, handler: {(alert: uialertaction!) in print("cancel")}) alertcontroller.addaction(somethingaction) alertcontroller.addaction(cancelaction) self.present(alertcontroller, animated: true, completion:{})
objective-c
uialertcontroller *alertcontroller = [uialertcontroller alertcontrollerwithtitle:@"\n\n\n\n\n\n" message:nil preferredstyle:uialertcontrollerstyleactionsheet]; cgfloat margin = 8.0f; uiview *customview = [[uiview alloc] initwithframe:cgrectmake(margin, margin, alertcontroller.view.bounds.size.width - margin * 4.0f, 100.0f)]; customview.backgroundcolor = [uicolor greencolor]; [alertcontroller.view addsubview:customview]; uialertaction *somethingaction = [uialertaction actionwithtitle:@"something" style:uialertactionstyledefault handler:^(uialertaction *action) {}]; uialertaction *cancelaction = [uialertaction actionwithtitle:@"cancel" style:uialertactionstylecancel handler:^(uialertaction *action) {}]; [alertcontroller addaction:somethingaction]; [alertcontroller addaction:cancelaction]; [self presentviewcontroller:alertcontroller animated:yes completion:^{}];
that being said, less hacky approach make own view subclass works uialertcontroller's uialertactionstyle layout. in fact, same code looks different in ios 8 , ios 9.
Comments
Post a Comment