Pregunta

Tengo un UIImageView en mi solicitud y me preguntaba cómo puedo mostrar una imagen en ella de manera pragmática y cambiarlo cuando quiera! Creo que mi principal problema es exactamente donde ponerlo! Si usted me podría mostrar qué código y cuando ello fuera muy útil! gracias!

EDIT: También si pragmáticamente puede cambiar el fondo en una imagen o incluso un color! ¡Gracias! o bien va a funcionar!

Edit2: aquí es mi código, que no sé dónde poner los porque siempre me dan un error

MainView.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface MainView : UIView {
    //static int r;
    int r;
    IBOutlet UIButton *myButton;
    IBOutlet UILabel *myTextLabel;
    IBOutlet UILabel *myTextLabel2;
    IBOutlet UIImageView *myImage;

}

@property (nonatomic, retain) UIButton *myButton;
@property (nonatomic, retain) UILabel *myTextLabel;
@property (nonatomic, retain) UILabel *myTextLabel2;
@property (nonatomic, retain) UIImageView *myImage;



- (IBAction)buttonclick;

//+(void) initialize;

@end

y

MainView.m

#import "MainView.h"
#include <stdlib.h>
#include <libc.h>


@implementation MainView

@synthesize myButton, myTextLabel, myTextLabel2, myImage;   


- (IBAction)buttonclick {

    r++;

    if(r == 1) {

        self.myTextLabel.text = @"word";
        self.myTextLabel2.text = @"def.";

    }else if(r == 2) {

        self.myTextLabel.text = @"word2";
        self.myTextLabel2.text = @"def2 ";  
    }

}

@end
¿Fue útil?

Solución

Para cambiar la imagen en sí, se puede escribir:

UIImage* myNewImage = ...;
myImageView.image = myNewImage;

Para cambiar el fondo de su UIImageView, se puede escribir:

myImageView.backgroundColor = [UIColor redColor];

... o cualquier otro UIColor que le gustaría, incluyendo otra imagen que se utiliza como un patrón.

Otros consejos

Si se implementa el método viewDidLoad () en su clase controlador de vista se puede establecer la imagen en la vista allí. Cuando este método se invoca automáticamente todos los IBOutlets se inicializará ya que le permite establecer myImageView.image.

Consulte viewDidLoad

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top