2010-10-19 20 views

Répondre

1

Bien sûr, utiliser un UIView personnalisé ou classe UIViewController et toutes vos vues sous-vue ou contrôleurs de vue de cela.

0
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]; 
0

Nous pouvons l'atteindre en utilisant l'étape suivante. 1. Créez un nouveau fichier avec la sous-classe 'UIView' et nommez-le 'customButom' 2. Ajoutez un fichier d'interface UIView et nommez-le customButtom.xib et liez le fichier customButtom avec xib. 3. Après cela, réglez la taille UIView sur Freedom dans le panneau utilitaire. Et définissez la largeur et la hauteur souhaitées. Dans cet exemple, je l'ai défini 160x50 J'ai créé un protocole, des propriétés et IBAction pour le handle d'événement.

//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