Ich habe an einer benutzerdefinierten Symbolleiste für eine App gearbeitet, die ich erstelle. Ich habe ein Problem mit der Größenanpassung der Symbolleiste, die Größe wird auf größeren Geräten wie einem iPad oder iPhone 6 korrekt, aber genauer gesagt, das Problem ist mit der Positionierung eines Schaltflächenelements, das in der Symbolleiste ist.objector-c iOS - Benutzerdefinierte Symbolleiste nicht Positionierung Schaltfläche wie erwartet
Unten ist ein Bild des Problems, das erfolgreich auf einem kleineren Gerät funktioniert. Working correctly on smaller device
Und hier ist die Ausgabe auf einem iPad: Incorrect Camera Position
Wie Sie aus den Screenshots, die Kamerataste Position nicht wie erwartet oder gewünscht ist, sehen kann.
Hier finden Sie Code, der die Symbolleiste Elemente einrichtet:
-(void)setupToolbar:(NSString *)buttonLabel
{ self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin; // HINZUGEFÜGT WERDEN, UM DEN UNTERSATZ ZU PLATZIEREN self.tintColor = [UIColor lightGrayColor];
/* Create custom send button*/
UIImage *buttonImage = [UIImage imageNamed:@"send.png"];
buttonImage = [buttonImage stretchableImageWithLeftCapWidth:floorf(buttonImage.size.width/2) topCapHeight:floorf(buttonImage.size.height/2)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font = [UIFont boldSystemFontOfSize:15.0f];
button.titleLabel.shadowOffset = CGSizeMake(0, -1);
button.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, 2);
button.contentStretch = CGRectMake(0.5, 0.5, 0, 0);
button.contentMode = UIViewContentModeScaleToFill;
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setTitle:buttonLabel forState:UIControlStateNormal];
[button addTarget:self action:@selector(inputButtonPressed) forControlEvents:UIControlEventTouchDown];
[button sizeToFit];
self.inputButton = [[UIBarButtonItem alloc] initWithCustomView:button];
self.inputButton.customView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
/* Disable button initially */
self.inputButton.enabled = NO;
//Camera
UIImage *buttonImageCam = [UIImage imageNamed:@"btnCamera.png"];
buttonImageCam = [buttonImageCam stretchableImageWithLeftCapWidth:floorf(buttonImageCam.size.width/2) topCapHeight:floorf(buttonImageCam.size.height/2)];
UIButton *btnCam = [UIButton buttonWithType:UIButtonTypeCustom];
btnCam.titleLabel.font = [UIFont boldSystemFontOfSize:15.0f];
btnCam.titleLabel.shadowOffset = CGSizeMake(0, -1);
btnCam.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, 2);
btnCam.contentStretch = CGRectMake(0.5, 0.5, 0, 0);
btnCam.contentMode = UIViewContentModeScaleToFill;
[btnCam setBackgroundImage:buttonImageCam forState:UIControlStateNormal];
[btnCam setTitle:buttonLabel forState:UIControlStateNormal];
[btnCam addTarget:self action:@selector(inputCamButtonPressed) forControlEvents:UIControlEventTouchDown];
[btnCam sizeToFit];
self.inputButtonCam = [[UIBarButtonItem alloc] initWithCustomView:btnCam];
self.inputButtonCam.customView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
/* Disable button initially */
self.inputButtonCam.enabled = YES;
/* Create UIExpandingTextView input */
self.textView = [[BHExpandingTextView alloc] initWithFrame:CGRectMake(40, 7, self.bounds.size.width - 70, 26)];
self.textView.internalTextView.scrollIndicatorInsets = UIEdgeInsetsMake(4.0f, 0.0f, 10.0f, 0.0f);
self.textView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
self.textView.delegate = self;
[self addSubview:self.textView];
/* Right align the toolbar button */
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *items = [NSArray arrayWithObjects: flexItem, self.inputButton,self.inputButtonCam, nil];
[self setItems:items animated:NO];
}
Ich habe versucht, die untergeordneten Elemente (Tasten) autosizingmasks Einstellung, aber das ist nicht erfolgreich überhaupt bewiesen und es hat mich eher stecken. Jede Hilfe, die helfen könnte, das Problem zu identifizieren, wäre dankbar. Danke.
Ich habe das ausprobiert und es macht leider keinen Unterschied zum Layout der Kamera Taste. – Ashley