Cocoa Touch - プログラムでUiImageViewを追加する?
-
28-09-2020 - |
質問
Objective-Cで新しいImageViewを作成して配置する方法:
ありがとう!
私はこれを試してみましたが、何もしないようです...
-(void)drawStars{ //uses random numbers to display a star on screen
//create random position
int xCoordinate = arc4random() % 10;
int yCoordinate = arc4random() % 10;
UIImageView *starImgView = [[UIImageView alloc] initWithFrame:CGRectMake(xCoordinate, yCoordinate, 58, 40)]; //create ImageView
starImgView.image = [UIImage imageNamed:@"star.png"];
[starImgView release];
.
このメソッドを私のViewControllerに置きました。CGのものを見るCore Graphicsや何かをインポートする必要がありますか?(とにかくコアグラフィックとは何ですか?)
解決
あなたはiPhoneのイメージビューについて尋ねています。正しい?それからこの
を試してくださいUIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
.
これは、100 x 50ディメンションのイメージビューを作成し、親ビューの位置特定(10,10)を作成します。
> uiimageview と uiview 。 ImageViewのimage プロパティ。
imgView.image = [UIImage imageNamed:@"a_image.png"];.
とあなたは contentmode uiviewのプロパティビュー内の画像にフィットする方法を設定します。たとえば、
を使用できます所望の画像をビューの中心に配置するための
imgView.contentMode = UIViewContentModeCenter。利用可能なContentModesはリストされていますこちら
他のヒント
別のビューへのサブビューとしてあなたのビューを追加していません。つまり、ビュー階層にはありません。
ビューコントローラでこれを行っていると仮定すると、次のように見えるかもしれません:
[self.view addSubview: imgView];
. (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.layer.frame.size.width, self.view.layer.frame.size.height)];
imgView.image = [UIImage imageNamed:@"emptyCart.jpeg"];
imgView.backgroundColor = [UIColor whiteColor];
imgView.contentMode = UIViewContentModeCenter;
[self.view addSubview: imgView];
}
. 値NSSArray
をNSString
、
私は答えを得ました:
//Display all images....
NSString *imgstring= [self.allimages objectAtIndex:indexPath.row];
cell.myimages.image=[UIImage imageNamed:imgstring]; //displaying Images in UIImageView..noproblem.
// Display all numbers...
cell.mylables.text=[NSString stringWithFormat:@"%@", [mysetobjectAtIndex:indexPath.row ]]; //showing results fine ArghyA..
. 所属していません StackOverflow