我想知道是否有办法使用 addSubview
将UIImageView放入另一个视图的特定区域这就是我的代码目前的样子,我想知道如何将图像添加到视图的特定位置,例如左上角(0,0)。
这就是我正在做的事情。
//...
jumpBar = [[JumpBarViewController alloc] initWithNibName:@"JumpBarViewController" bundle:[NSBundle mainBundle]];
jumpBarContainer = [[UIView alloc] initWithFrame:CGRectMake(0.0, 480.0, (jumpBarHeight + 49.0), 320.0)];
[jumpBarContainer addSubview:jumpBar.view];
[self.view insertSubview:jumpBarContainer belowSubview:actionTabBar];
// Add jumpBar shade
switch (jumpBarHeight) {
case 103:
{
NSLog(@"one row");
UIImageView *smlShader = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1-row-top-bg.png"]];
[jumpBarContainer addSubview:smlShader]; // how do i add this to the top left of jumBarContainer?
}
//...
任何帮助将不胜感激:)
答案 0 :(得分:2)
设置UIImageView框架:
UIImageView *smlShader = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1-row-top-bg.png"]];
smlShader.frame = CGRectMake(x,y,w,h); //Change the value of the frame
[jumpBarContainer addSubview:smlShader];