IPhone DevelopmentThe implementation of the Code is the content to be introduced in this article. Should you be interested in it? This article describes how to create a jiugongge bucket. Let's take a look at the details. Many people in CocoaChina are asking, but it's actually very simple.ImageThe Code is as follows.
:
The core is the two methods:
- // Power by ieliwb.com
- -(Void) viewDidLoad {
- [Super viewDidLoad];
- NSArray * imageNames = [NSArray arrayWithObjects:
- @ "Ico_mobile.png ",
- @ "Ico_idcard.png ",
- @ "Ico_postcode.png ",
- @ "Ico_flight.png ",
- @ "Ico_translate.png ",
- @ "Ico_phone.png ",
- @ "Ico_car.png ",
- @ "Ico_health.png ",
- @ "Ico_bjxm.png", nil];
- UIButton * Btn;
- For (int I = 0; I <9; I ++ ){
- CGRect frame;
- Btn = [[UIButton buttonWithType: UIButtonTypeCustom] retain];
- [Btn setImage: [UIImage imageNamed: [imageNames objectAtIndex: I] forState: UIControlStateNormal]; // set the button Image
- Btn. tag = I;
- Frame. size. width = 59; // you can specify the coordinate and size of a button.
- Frame. size. height = 75;
- Frame. origin. x = (I % 3) * (59 + 32) + 40;
- Frame. origin. y = floor (I/3) * (75 + 24) + 40;
- [Btn setFrame: frame];
- [Btn setBackgroundColor: [UIColor clearColor];
- [Btn addTarget: self action: @ selector (btnPressed :) forControlEvents: UIControlEventTouchUpInside];
- [Self. view addSubview: Btn];
- [Btn release];
- }
- }
- // Response button event
- -(Void) btnPressed :( id) sender {
- UIButton * Btn = (UIButton *) sender;
- Int index = Btn. tag;
- Switch (index ){
- Case 0:
- If (mobileController = nil)
- MobileController = [[MobileController alloc] init];
- [Self. navigationController pushViewController: mobileController animated: YES];
- Break;
- // Several other controllers are similar
- }
- }
The following figure shows how to modify the jiugongge Background:
- - (void)loadView {
- UIImageView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
- [contentView setImage:[UIImage imageNamed:@"subview_9_bg.png"]];
- [contentView setUserInteractionEnabled:YES];
- self.view = contentView;
- [contentView release];
- }
UINavigationBar backgroundImageThis can be achieved as follows:
- @implementation UINavigationBar (CustomImage)
- - (void)drawRect:(CGRect)rect {
- UIImage *image = [UIImage imageNamed: @"top_bg.png"];
- [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- }
- @end
Summary:IPhone DevelopmentThe content of code implementation of jiugongge has been introduced. I hope this article will help you!