UIButtonTypeCustom (셰이프) 형식의 UIButton을 만들고 싶습니다. 글꼴을 지정해야하기 때문에 button.titleLabel을 사용하여 제목을 지정하고 싶습니다. 다음 코드는 작동해야하지만 보이지는 않습니다. 레이블이 나타나지 않으며 마침표가 없습니다.iOS : UIButton titleLabel - 모든 작업을 수행합니까?
UIImage *editButtonImage = [UIImage imageNamed: @"editButton.png"];
float width = editButtonImage.size.width;
float height = editButtonImage.size.height;
UIButton *editButton = [UIButton buttonWithType: UIButtonTypeCustom];
editButton.frame = CGRectMake(0, 0, width, height);
[editButton setBackgroundImage: editButtonImage forState: UIControlStateNormal];
editButton.adjustsImageWhenHighlighted = YES;
editButton.titleLabel.text = @"Edit";
editButton.titleLabel.textColor = [UIColor whiteColor];
editButton.titleLabel.textAlignment = UITextAlignmentCenter;
editButton.titleLabel.font = [UIFont fontWithName: @"Helvetica" size: 14];
[self.view addSubview: editButton];
모두는 항상 setTitle : forState :를 사용한다고 말합니다.하지만 나는 싫어하는 글꼴을 제공합니다. titleLabel 메서드는 더 이상 사용되지 않습니다.
이전에 여러 번 실행 해 본 적이 있지만 항상 해결되었지만 실제로 해결하고 싶습니다. 어떤 아이디어?
titleLabel을 사용하여 설정할 수없는 것은 실제 텍스트 값입니다. 그건 나에게 이상한 것 같지만 괜찮아. – Amagrammer
처음에는 반 직관적입니다. 겉으로보기에, 레이블의'text' 속성을 설정하는 것은'-setTitle : forState'를 호출하기위한 바로 가기 일 뿐이지 않습니다. – LucasTizma
마찬가지로 titleLabel의 textColor 속성을 직접 설정할 수 없지만 setTitleColor : forState : 메서드를 사용해야합니다. 이것을 언급 해 주셔서 감사합니다. 문서에 없기 때문입니다. – arlomedia