I am working with alertViews to load to them different objects, such as textFields and others.
With textFields there is no problem. I have successfully added a UIPickerView as a subview of my alertView and I had resized the alertView.frame to hold the pickerView properly, but then the title and the button in the alertView are not centered.
I tried with many of the options [alertView …function…] but none seems to work with this issue. This looks bad in a custom sized alertView. Any suggestions?
Thanks folks!
to solve the Title issue, I got inspiration from this post: Custom AlertView With Background
First of all, when the App presents the alertView, I called a NSLog to get:
_titleLabel‘s width_titleLabel‘s starting position (MinX and MinY)then I resized the
_titleLabelframe and that was all!textAlignmentis Center by default so all I had to do was resize the label frame. other possible method is to useY value is 0 because I didn’t want it to move vertically. But the described method is cleaner to me.
so what I added to the method that creates&presents my alertView was this:
NOTE: this code HAS to go BEFORE the addition of any additional view to the alertView!
as for the button, i found in the UIAlertView.h file that buttons cannot be customized…so if someone has any tip on this issue, any help will be appreciated.
hope this helps someone else!
UPDATE: As I mentioned, Apple said buttons in alertViews cannot be customized, so there are two alternatives: create a custom button and add it as subview or have no button at all. In my case I did so, and called
[myAlertView dismissWithClickedButtonIndex:-1 animated:YES]in thedidSelectRow...inComponentpart of the pickerView code.This worked for me just fine, but I am open to new ideas!!
See ya!