我正在开发一个 iphone 应用程序,在我的所有视图中我都需要一个控件,比如说一个按钮。
我想知道在 Iphone 开发中是否有与 Asp.net 母版页相同的浓度?
塔
当然,使用自定义 UIView 或 UIViewController 类并从中查看所有视图或视图控制器。
1. Create a viewController class as TopViewController and delete already created view first then add a view from IB (drag drop) and connect to File's Owner (view) then set height and width what you want.
2. Create object of TopViewController like-
TopViewController *topVC=[[TopViewController alloc] initWithNibName:@"TopViewController" bundle:nil];
[self.view addSubView:topVC.view];
我们可以使用以下步骤来实现它。1. 创建一个新文件,其子类为“UIView”,并将其命名为“customButom” 2. 添加一个 UIView 接口文件并将其命名为 customButtom.xib,并将 customButtom 文件与 xib 链接。3. 之后在实用面板中将 UIView 大小设置为 Freedom。并设置您想要的宽度和高度。在此示例中,我将其设置为 160x50 我为事件句柄创建了协议、属性和 IBAction。
//customButton.h
#import<UIKit/UIKit.h>
// createdcustomButtonDelegate protocol
@protocolcustomButtonDelegate<NSObject>
-(void)performButtonClicked;
@end
@interfacecustomButton : UIView
@property(nonatomic,retain)id<customButtonDelegate>delegate;
-(IBAction)customButtonClicked:(id)sender;
@end
//customButton.m Implemented properties and button action `
#import"customButton.h"
@implementationcustomButton
-(id)initWithFrame:(CGRect)frame {
self = [superinitWithFrame:frame];
if (self) {
UIView *buttonView =[[[NSBundlemainBundle]loadNibNamed:@"customButton"owner:selfoptions:nil] objectAtIndex:0];
[selfaddSubview:buttonView];
}
returnself;
}
-(IBAction)customButtonClicked:(id)sender {
if (self.delegate != nil) {
[self.delegateperformButtonClicked];
}
}
@end
// Viewcontroller.h Import customButton.h file in our view controller and add delegate `
#import<UIKit/UIKit.h>
#import"customButton.h"
@interfaceViewController : UIViewController<UIAlertViewDelegate,customButtonDelegate>
@end
// Viewcontroller.m file
@interfaceViewController ()
@end
@implementationViewController {
customButton *buttonView;
}
- (void)viewDidLoad {
[superviewDidLoad];
// we can display / set our custom view on specific location on view. just need to provide your desire Frame
//creating customButton object and added this object to our view.
buttonView = [[customButtonalloc]initWithFrame:CGRectMake(80, 465, 160, 50)];
buttonView.delegate = self;
[self.viewaddSubview:buttonView];
}
#pragma mark custombutton delegate
-(void)performButtonClicked {
NSLog(@"Perform whatever you want to");
}
@end