您的位置:首页 > 其它

BubbleButtonView - 将字符串分解为多个气泡然后排列到一个 view上

2013-03-11 00:49 274 查看
https://github.com/bennyguitar/iOS----BubbleButtonView

BubbleButtonView

Dynamically fill a subclassed UIView with rounded-corner UIButtons based off of an array of strings. This class also sequentially animates the adding and removing of buttons for a nice UI touch.




Installation

Drag the included
BBView.m, BBView.h
files
into your project. Then, include the following frameworks under Link Binary With Libraries:

QuartzCore.framework

Using
BBView

Make sure to
#import BBView.h
into whatever
ViewController you want to use the BubbleButtonView in.

BBView works by taking an array of NSStrings and creating a UIButton for each one. The buttons are systematically added to the View such that they will fit on the line next to the last one, or if it won't fit, added on a new line. Because BBView's animations
work via subviews (each UIButton is a subview of BBView), you should make BBView the lowest level possible - don't add more UI elements to BBView. Keep it simple.

Begin by making a new UIView in your ViewController.xib, and changing its class to BBView (through the identity inspector in the right bar). Drag this over to your ViewController.h to connect it up. In your .h

@interface ViewController : UIViewController <BBDelegate> {
  __weak IBOutlet BBView *bubbleView;
}


Notice we added the BBDelegate to your ViewController, and make sure you set bubbleView's delegate to self inside ViewDidLoad or wherever you instantiate your BBView.

Now, to fill the BBView with your buttons, first create an NSArray of NSStrings. Ideally, this would tie into data you wish to manipulate - this part is entierly dependent on your project and what you wish to do. BBView also has arguments for the background
color, text color and font-size for each button. This is for UI and again, entirely up to you. This is the function you should call inside your ViewController:

[bubbleView fillBubbleViewWithButtons:NSArray bgColor:UIColor textColor:UIColor fontSize:float];


Each UIButton is given a tag based on the index of the array you pass in. Use the
-(void)didClickBubbleButton:(UIButton
 *)bubble;
method from the BBDelegate to manipulate your data. Use
bubble.tag
to
do so.

Reap
What I Sow!

This project is distributed under the standard MIT License. Please use this and twist it in whatever fashion you wish - and recommend any cool changes to help the code.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐