2012-11-13 68 views
0

我有一個UIBarButtonItem,我想擁抱屏幕的左邊。我試過在按鈕和其他配置之前放置一個固定的barbuttonwidth = 0,但在按鈕和x = 0之間總是有幾個像素。位置UIBarbuttonItem非常左

我也試着改變的UIButton

UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
moreButton.frame = CGRectMake(0, 0, 60, 35); 
[moreButton setImage:[UIImage imageNamed:@"Morebutton"] forState:UIControlStateNormal]; 
moreButton.imageEdgeInsets = UIEdgeInsetsMake(0, -8, 0, 8); 
[moreButton addTarget:self action:@selector(pressedMoreButton:) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *moreBar = [[[UIBarButtonItem alloc] initWithCustomView:moreButton] autorelease]; 

imageInset但攻靠近屏幕邊緣不會觸發selector(大概是因爲只有圖像被移動而不是按鈕本身)並增加size的按鈕並不會影響按鈕與左側之間的差距。

謝謝

回答

0

試着把你的按鈕放到容器視圖並改變視圖上按鈕的位置。

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
    button.contentMode = UIViewContentModeScaleAspectFit;  
    button.frame= CGRectMake(-4.0, 0.0, 30, 30); 
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; 

    UIView *v=[[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, cellTextSize.width+10, buttonImage.size.height)] autorelease]; 
    v.backgroundColor = [UIColor clearColor]; 
    [v addSubview:button]; 

    return [[[UIBarButtonItem alloc] initWithCustomView:v] autorelease]; 
+0

UIView仍然沒有達到最左邊,所以即使我移動按鈕,觸摸不在UIView內部,所以觸摸事件不會觸發。 –

+0

你可以發佈任何視覺信息。它的外觀如何? –