Bagaimana cara menyesuaikan UIToolbar dengan tombol yang berisi gambar berwarna?

Saya punya dua pertanyaan tentang UIToolbar:

1: Saya telah membaca banyak jawaban Stackoverflow tentang cara menggunakan tombol dengan gambar khusus (berwarna) di UIToolbar. Saya telah mencoba meletakkan tampilan (hack) di atas UIToolbar dan meletakkan tombol-tombol dengan gambar di dalamnya, tetapi gagal. Saat ini saya terjebak. Bagaimana Anda bisa mencapai hal ini?

2: Apakah ada cara agar banyak tombol dalam keadaan "ditekan" secara bersamaan? Fungsi yang ingin saya capai adalah tombol berbeda dengan jenis penyortiran berbeda.


person Christofffer    schedule 12.01.2011    source sumber


Jawaban (2)


Ok jawabannya terpecahkan sendiri... ini dia:

Dapatkah saya memiliki UIBarButtonItem dengan gambar berwarna?

-(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

Saya tahu jawaban dari persyaratan kedua Anda.

di IB klik pada tampilan dan di inspektur centang aktifkan beberapa sentuhan.

Bersulang

person rdp    schedule 12.01.2011