Ich bin schon eine Weile auf dieser Sache fest, so dass jede Hilfe sehr geschätzt wird.Hinzufügen einer UIImageView zu einer UIView
Ich habe im Grunde genommen eine Klasse namens Shape, die eine UIView
ist, und ich möchte eine UIImageView
zu dieser UIView
hinzufügen.
Hier ist meine .h-Datei:
@interface Shape : UIView {
int blockWidth;
int blockHeight;
NSString *colour;
IBOutlet UIImageView *blockView;
}
@property (nonatomic, retain) IBOutlet UIImageView *blockView;
@property (nonatomic, retain) NSString *colour;
-(void)setColour:(NSString *)colour;
-(void)createShape:(int)blocksX :(int)blocksY;
@end
Und hier ist meine .m-Datei:
@implementation Shape
@synthesize blockView;
@synthesize colour;
- (void)setColour:(NSString *)colour{
NSLog(@"Colour: %@", colour);
}
-(void)createShape:(int)blocksX :(int)blocksY{
self.frame = CGRectMake(0, 0, 200, 200);
blockView.frame = CGRectMake(0, 0, 100, 100);
self.backgroundColor = [UIColor greenColor];
blockView.backgroundColor = [UIColor redColor];
[self addSubview:blockView];
}
- (void)dealloc {
[blockView release];
[colour release];
[super dealloc];
}
@end
Vielen Dank!
Hey nochmal Entschuldigung wenn das verwirrend ist, aber ich versuche diesen cisc Code ins Ziel zu portieren, der obige Code ist mein erster Versuch und ist offensichtlich nicht wo ich fertig bin aber du kannst hoffentlich sehen was ich versuche zu erreichen, sorry, aber im völlig neu in Objective C, und es ist ganz anders als andere Sprachen, die ich verwenden bin: S
public class Shape : UIView
{
public UIImageView blockView;
private int blockWidth = 40;
private int blockHeight = 40;
public Shape (int startX, int startY ,string colour, int blocksX, int blocksY)
{
Console.WriteLine("Colour: "+colour+" Blocks: "+blocksX+" "+blocksY);
this.Frame = new RectangleF(startX,startY,blockWidth*blocksX,blockHeight*blocksY);
this.UserInteractionEnabled = true;
for(int i = 0; i<blocksX; i++)
{
for(int j = 0; j<blocksY; j++)
{
blockView = new UIImageView(UIImage.FromFile("Images/Blocks/"+colour+"block.jpg"));
blockView.Frame = new RectangleF(blockWidth*i,blockHeight*j,blockWidth,blockHeight);
Console.WriteLine("I: "+i+" J: "+j);
this.AddSubview(blockView);
}
}
}
haben Sie versucht, ein tatsächliches Bild hinzuzufügen? –
Können Sie die Codeblock-Taste verwenden? Es macht Ihren Code für alle leichter lesbar. Auch wo versuchst du das Bild hinzuzufügen? – BOMEz