จะปรับแต่ง UIToolbar ด้วยปุ่มที่มีรูปภาพสีได้อย่างไร

ฉันมีสองคำถามเกี่ยวกับ UIToolbar:

1: ฉันได้อ่านคำตอบของ Stackoverflow มากมายเกี่ยวกับวิธีใช้ปุ่มกับรูปภาพที่กำหนดเอง (สี) ใน UIToolbar ฉันได้ลองวางมุมมอง (แฮ็ค) ไว้ด้านบนของ UIToolbar แล้ววางปุ่มที่มีรูปภาพอยู่ในนั้น แต่ล้มเหลว ตอนนี้ฉันติดอยู่ คุณจะทำสิ่งนี้ให้สำเร็จได้อย่างไร?

2: มีวิธีให้ปุ่มหลายปุ่มอยู่ในสถานะ "กด" พร้อม ๆ กันหรือไม่? ฟังก์ชั่นที่ฉันต้องการทำให้สำเร็จคือปุ่มต่างๆ ที่มีการเรียงลำดับประเภทต่างๆ


person Christofffer    schedule 12.01.2011    source แหล่งที่มา


คำตอบ (2)


ตกลงคำตอบแก้ไขได้เอง ... นี่คือ:

ฉันขอ UIBarButtonItem พร้อมรูปภาพสีได้ไหม

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated]; 
    toolbar = [[UIToolbar alloc] init];
    toolbar.barStyle = UIBarStyleDefault;

    //Set the toolbar to fit the width of the app.
    [toolbar sizeToFit];

    //Calculate the height of the toolbar
    CGFloat toolbarHeight = [toolbar frame].size.height;

    //Get the bounds of the parent view
    CGRect rootViewBounds = self.parentViewController.view.bounds;

    //Get the height of the parent view.
    CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);

    //Get the width of the parent view,
    CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);

    //Create a rectangle for the toolbar
    CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);

    //Reposition and resize the receiver
    [toolbar setFrame:rectArea];

    //Create a button
    UIImage *image = [UIImage imageNamed:@"colorImage.png"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );    
    [button setImage:image forState:UIControlStateNormal];
    [button addTarget:self action:@selector(myAction) forControlEvents:UIControlEventTouchUpInside];    
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

    [toolbar setItems:[NSArray arrayWithObjects:barButtonItem,nil]];

    //Add the toolbar as a subview to the navigation controller.
    [self.navigationController.view addSubview:toolbar];
}

-(void)myAction{
    NSLog(@"jippiii");
}
person Christofffer    schedule 12.01.2011

ฉันรู้คำตอบของข้อกำหนดที่ 2 ของคุณ

ใน IB คลิกที่มุมมองและในตัวตรวจสอบตรวจสอบการเปิดใช้งานหลายสัมผัส

ไชโย

person rdp    schedule 12.01.2011