- 在現有的UIView的頂部,加載背景圖像
- 從一疊卡片圖像(大圖),剪卡1張(的一部分一個大的圖像),並且卡上的背景圖像的頂部
下面的代碼工作
- 我在做對吧?它是這樣完成的嗎?
- 我用過的所有步驟真的需要嗎?我有一個強烈的懷疑我變得更加複雜,那麼它需要
謝謝您的時間
// Define overall UIView area and create a view
UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
// Gain access to background image
UIImage *backgroundImage = [UIImage imageNamed:@"green_background.jpg"];
// Put background image on top of a
UIImageView *myImageView = [[UIImageView alloc] initWithImage:backgroundImage];
// So now we have the view of some size with some image bahind it
[background addSubview:myImageView];
// #####################################################################
CGRect positionOnParentView = CGRectMake(40, 40, 50, 130);
CGImageRef bigImage = [UIImage imageNamed:@"cards.png"].CGImage;
CGImageRef partOfABigImage = CGImageCreateWithImageInRect(bigImage, CGRectMake(0, 0, 200, 50));
// get an image to be displayed
UIImage *partOfImage = [UIImage imageWithCGImage:partOfABigImage];
// Put it on it's onw view
UIImageView *cardImage = [[UIImageView alloc] initWithImage:partOfImage];
// create a UIview and add image
UIView *card = [[UIView alloc] initWithFrame:positionOnParentView];
[card addSubview:cardImage];
[background addSubview:card];
[[self view] addSubview:background];
你可能想看看自動引用計數(ARC),所以你不需要發佈的東西;) – Faser