hackiftekhar / IQActionSheetPickerView

ActionSheet with UIPickerView
MIT License
205 stars 76 forks source link

Button Cancel And Ok Show Not Correct Frame #22

Closed Hiep-HN closed 7 years ago

Hiep-HN commented 7 years ago

Custom UIBarButtonItem in IQPickerView.m

//UIToolbar { _actionToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, -4, 320, 44)]; // _actionToolbar.barStyle = UIBarStyleDefault;//UIBarStyleBlackTranslucent; [_actionToolbar sizeToFit];

        CGRect toolbarFrame = _actionToolbar.frame;
        toolbarFrame.size.height = 44;
        _actionToolbar.frame = toolbarFrame;

        NSMutableArray *items = [[NSMutableArray alloc] init];

        //  Create a cancel button to show on keyboard to resign it. Adding a selector to resign it.
        UIButton *cancelView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        [cancelView setTitle:NSLocalizedString( @"キャンセル" , nil) forState:UIControlStateNormal];
        cancelView.titleLabel.font= [UIFont boldSystemFontOfSize: 12];
        [cancelView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cancelView addTarget:self action:@selector(pickerCancelClicked:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithCustomView:cancelView];

// UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"キャンセル", nil) // style:UIBarButtonItemStylePlain target:self action:@selector(pickerCancelClicked:)]; [items addObject:cancelButton];

        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _actionToolbar.frame.size.width-66-57.0-16, 44)];
        _titleLabel.font = [UIFont fontWithName:@"HiraginoSans-W6" size:12];
        [_titleLabel setBackgroundColor:[UIColor clearColor]];
        [_titleLabel setTextAlignment:NSTextAlignmentCenter];
        [_titleLabel setText:title];
        [_titleLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

        UIBarButtonItem *titlebutton = [[UIBarButtonItem alloc] initWithCustomView:_titleLabel];
        titlebutton.enabled = NO;

        //  Create a fake button to maintain flexibleSpace between doneButton and nilButton. (Actually it moves done button to right side.
        UIBarButtonItem *nilButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        [items addObject:nilButton];

        //  Create a done button to show on keyboard to resign it. Adding a selector to resign it.
        UIButton *okView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        [okView setTitle:NSLocalizedString(@"OK",nil) forState:UIControlStateNormal];
        okView.titleLabel.font= [UIFont boldSystemFontOfSize: 12];
        [okView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [okView addTarget:self action:@selector(pickerDoneClicked:) forControlEvents:UIControlEventTouchUpInside];

// UIBarButtonItem doneButton =[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"OK", @"") // style:UIBarButtonItemStylePlain target:self action:@selector(pickerDoneClicked:)]; UIBarButtonItem doneButton = [[UIBarButtonItem alloc] initWithCustomView:okView]; [items addObject:doneButton];

        //  Adding button to toolBar.
        [_actionToolbar setItems:items];

        [self addSubview:_actionToolbar];
    }
hackiftekhar commented 7 years ago

@Hiep-HN Can you please share screenshot?

Hiep-HN commented 7 years ago

Dear Sir,

About this screenshot this issue: [image: Hình ảnh nội tuyến 1]

2016-10-27 19:13 GMT+07:00 Mohd Iftekhar Qurashi notifications@github.com:

@Hiep-HN https://github.com/Hiep-HN Can you please share screenshot?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hackiftekhar/IQActionSheetPickerView/issues/22#issuecomment-256624218, or mute the thread https://github.com/notifications/unsubscribe-auth/AHvmREcpLTRx8QZgzbt93QkXUBQW2taBks5q4JWHgaJpZM4KiERX .

Thanks & Best Regards, Continue live and attempt=.=

Họ và Tên:Huỳnh Ngọc Hiệp.SĐT:01222 015 585.

_Skype: huynhngochiepgivelove Mail: m mr.hiepuit@gmail.comr.hiepuit@gmail.com r.hiepuit@gmail.com FB: Love Give

memovillalobos commented 7 years ago

Hello, While this is fixed I wanted to share a temporary (and not-too-pretty) solution for this:

UIButton *leftButton = [[[picker.subviews firstObject].subviews firstObject].subviews firstObject]; [leftButton setTitleEdgeInsets: UIEdgeInsetsMake(0.0, 10.0, 0.0, -10.0f)]; UIButton *rightButton = [[[picker.subviews firstObject].subviews lastObject].subviews firstObject]; [rightButton setTitleEdgeInsets: UIEdgeInsetsMake(0.0, -10.0, 0.0, 10.0f)];

Just change the 10.0 with whatever size you want for each side's margin.

Hope this helps!

hackiftekhar commented 7 years ago

This is now fixed in master branch.