开发者

Misplacement of contents of UIView

I have a UIView and UIButton (declared in viewDidLoad: method of RootViewcontroller. ).

UIView  *geopointView = [[UIView alloc] initWithFrame:CGRectMake(0, 320, 120, 100)] ;
UIButton *mybutton = [[UIButton alloc] initWithFrame:CGRectMake(0, 330, 120, 30)] ;

mybutton is added to geopointView.

  [geopointView addsubView:mybutton];

Finally UIView is added to RootViewController in method showTheView (defined in rootViewController)

-(void) showTheView{
    [self.view adds开发者_StackOverflow中文版ubView:geopointView];
}

but when this method is called,I find that both mybutton and geopointView are visible but mybutton is not placed inside of geopointView. mybutton's bounds now appear as CGRectmake(10, 250, 120, 30);

Can anyone please tell what I am missing here. Thanks for any help in advance.


try this

  UIbutton *mybutton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 120, 30)] ;


The frame of your button should be relative to the parent's bounds, but it appears to be relative to the screen. If you want your button to be inside the geopointView it needs to have x, y coordinates that fit within the width (120) and height (100) of geopointView, so something like this will put it in the top left corner (0,0) of geopointView:

UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0,0,120,30)];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜