2011-11-11 2 views

risposta

23

Se si desidera aggiungere l'UIImage al UIView, allora avete bisogno di un UIImageView inbetween l'UIView e UIImage, come ad esempio:

UIImage *image = [[UIImage alloc] init]; 
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; 
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; 
[iv setImage:image]; 
[v addSubview:iv]; 

Si noti che quanto sopra è codice appena manichino e ho creato tutto Elementi dell'interfaccia utente con una cornice zero.

+0

Grazie. Quale metodo di 'UIControler' dovrebbe contenere questo codice? – JAM

+0

In genere viewDidLoad –

+0

cosa dire del rilascio di v e iv? non devi farlo? – hanumanDev

0

Se si desidera aggiungere UIImage a UIView programatically è possibile aggiungere direttamente sull'immagine per vedere, Come ad esempio:

UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)]; 

customView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"YourImage.png"]]; 

[self.view addSubview:customView];