开发者

UIAlertView replacement

开发者 https://www.devze.com 2023-02-05 19:35 出处:网络
It seems that I am always fighting with UIAlertView to make it do what I want.I\'m done fighting - are there any robust UIAlertView replacements with the following features, or will I need to write my

It seems that I am always fighting with UIAlertView to make it do what I want. I'm done fighting - are there any robust UIAlertView replacements with the following features, or will I need to write my own?:

  • ability to customize the alert-view size/position
  • ability to change the layout of the buttons (stacked vs. side-by-side)
  • ability to prompt users for input via UITextField or UITextView
  • resizing / repositioning behavior when the keyboard appears
  • ability to have a UITextView for scrolling text
  • pixel-perfect copy of UIAlertView for basic display开发者_JS百科
  • ideally interface compatible with UIAlertView - i.e. it is a drop-in-replacement.

I've found a few blog and stackoverflow posts which implement customizations on a UIAlertView - this is NOT what I want. Nor do I want a guide on how to implement a custom AlertView -- I know how, I just want to find one that is already community maintained. I want a ground-up replacement that is safe for App Store submission and future-proof against UIAlertView changes (yes, I've been burnt...)

Please respond with comments if you have suggestions for other desirable features.


Answering my own question.

I searched high and low for a prefab UIAlertView project that offered the features I was looking for. I'm sure they exist -- I've seen apps with great alerts. Their authors must not be sharing - which is totally fine, I understand.

So I wrote my own. TSAlertView is a ground-up implementation of a modal alert view that is interface-compatible with UIAlertView. In terms of visual look, while it is not a pixel-perfect copy, it comes very close. The features it offers are basically what I outlined in the original question:

  • ability to set the display-width and max-height of the alert view. This allows me to have nicer looking alerts on iPad.

  • ability to specify the layout of the buttons (stacked vs. side-by-side), even if there are only two buttons. This always bothered me with UIAlertView -- if I had two buttons they were always placed side-by-side. A big problem if the button text didn't fit.

  • ability to prompt users for input via a UITextField. Once in a while you just need a quick and dirty way to prompt the user to enter something.

  • resizing / repositioning behavior when the keyboard appears. (happens when prompting for user-input)

  • ability to have a UITextView for scrolling text. Can explicitly set this option instead of relying on UIAlertView to swap in a UITextView for long text.

  • near pixel-perfect copy of UIAlertView for basic display.

  • support for custom backgrounds

  • is interface compatible with UIAlertView - i.e. it is a drop-in-replacement.

I've used a handful of great open-source projects in my code in the last year. My two favorites are MBProgressHUD and MGSplitViewController, each hosted at github. I decided to share TSAlertView in the same manner.

https://github.com/TomSwift/TSAlertView

The initial implementation surely has some bugs. I haven't used it in a shipping project yet, but I am using it in my current project to be completed in a few weeks. If you want to try using it yourself, please feel free. Post any issues on github, or better yet, submit a fix.

Enjoy!

Here are some screenshots showing 1) 2 stacked buttons 2) input capability 3) explicit width setting

UIAlertView replacement

UIAlertView replacement

UIAlertView replacement


Check out Smart Alert View, it's open-source.


Check my own Alert view replacement - get app here. https://github.com/FeminaErnest/GeekyFemi. Good luck

0

精彩评论

暂无评论...
验证码 换一张
取 消