UIButton의 제목 속성이 올바르게 기록되지만 버튼을 하위보기로 추가 할 때 표시되지 않습니다.

user3344977

내가 만든 UIButton이 있고 성공적으로 하위 뷰로 추가하고 화면에서 볼 수 있습니다. 문제는 다음을 사용하려고 할 때입니다.

[myButton setTitle:@"My Title" forState:UIControlStateNormal];

앱을 실행할 때 버튼에 제목이 표시되지 않습니다. 위의 방법을 사용한 후 버튼의 제목을 NSLog하면 실제로 전달하는 제목으로 설정됩니다.

여기 내 코드가 있습니다. 이것은 UIView 하위 클래스 안에 있습니다. 이 논리 중 일부는 UIView 하위 클래스에 속하지 않을 수 있지만 가능한 한 빨리 작동하도록 노력하고 있습니다.

// Set the view's frame, background color, corner radius
self.frame = CGRectMake(45, 200, 235, 187);
self.backgroundColor = [UIColor whiteColor];
self.layer.borderWidth = 1;
self.layer.borderColor = [UIColor grayColor].CGColor;
self.layer.cornerRadius = 5;

// Create the popup's body text label
self.popupBodyTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 150)];
self.popupBodyTextLabel.text = @"Text goes here.";

// Add text view to popup's subviews
[self addSubview:self.popupBodyTextLabel];

// Create ok button
UIButton *myButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 143, 120, 44)];
myButton.backgroundColor = [UIColor whiteColor];
myButton.layer.borderWidth = 1;
myButton.layer.borderColor = [UIColor grayColor].CGColor;
[myButton setTitle:@"OK" forState:UIControlStateNormal];


// Round the button's bottom left corner
UIBezierPath *myButtonMaskPath = [UIBezierPath bezierPathWithRoundedRect:myButton.bounds byRoundingCorners:(UIRectCornerBottomLeft) cornerRadii:CGSizeMake(5.0, 5.0)];

CAShapeLayer *okButtonMaskLayer = [[CAShapeLayer alloc] init];
myButtonMaskLayer.frame = myButton.bounds;
myButtonMaskLayer.path = myButtonMaskPath.CGPath;
myButton.layer.mask = myButtonMaskLayer;


// Add selector to button
[myButton addTarget:self action:@selector(myButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

// Add button to subviews
[self addSubview:myButton];

// Create the background view
self.backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
self.backgroundView.backgroundColor = [UIColor grayColor];
self.backgroundView.alpha = 0.5f;

// Show our new views
[[[UIApplication sharedApplication] keyWindow] addSubview:self.backgroundView];
[[[UIApplication sharedApplication] keyWindow] addSubview:[MPPopupView shared]];
Fionashoff

버튼 제목을 설정하는 코드가 맞으 므로이 코드를 사용하여 제목 색상 을 설정하십시오.

   [myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관