나는 MacOS 앱을 만들었으며 NSSearchField (searchField)의 글꼴을 스타일링하는 데 문제가 있습니다. 다음과 같이 내 코드는 지금까지 있습니다 :스타일 자리 표시 자 텍스트 NSSearchField 및 NSTextField?
하나의 주요의 ViewController 클래스의 상단에 선언있는 viewDidLoad로 선언
let normalTextStyle = NSFont(name: "PT Mono", size: 14.0)
let backgroundColour = NSColor(calibratedHue: 0.6,
saturation: 0.5,
brightness: 0.2,
alpha: 1.0)
let normalTextColour = NSColor(calibratedHue: 0.5,
saturation: 0.1,
brightness: 0.9,
alpha: 1.0)
:
searchField.backgroundColor = backgroundColour
searchField.textColor = normalTextColour
searchField.font = normalTextStyle
searchField.centersPlaceholder = false
searchField.currentEditor()?.font = normalTextStyle
let attrStr = NSMutableAttributedString(string: "Search...",
attributes: [NSForegroundColorAttributeName: normalTextColour])
searchField.placeholderAttributedString = attrStr
일반적으로이 하나 개의 조건을 제외하고 작동합니다 때 검색 필드에 포커스가 있지만 검색어가 입력되지 않았습니다. 이 경우 자리 표시 자 텍스트의 색이 맞지만 글꼴이 기본값으로 돌아갑니다 (Helvetica 12 포인트?). 무언가가 입력되거나 필드의 초점이 사라지 자마자 올바른 글꼴이 다시 사용됩니다.
나는 현재 설정되지 않은 일종의 글꼴이나 색상 설정을 Apple 문서를 통해 살펴 보려고 노력하지 않았습니다. 코코아 바인딩과 관리자의 일반 설정을 포함하여 인터페이스 작성기에서 찾을 수있는 모든 글꼴 설정을 살펴 보았습니다.
currentEditor의 값을 설정해야합니까? 나는 텍스트가 입력되면 폰트가 바뀌기 때문에 나는 추측하고있다. 나는 갇혀있다 - 아무도 도와 줄 수 있는가?
편집 : 이제 NSTextField로 시도했지만 결과는 같습니다. 누구든지 아이디어가 있습니까?
당신은 검색 창 역할을하는의 UITextField를 만들 수 있으며, 너를 기쁘게하는 방법. 검색 막대는 내 이해에서 적절하게 사용자 정의하기가 훨씬 어렵습니다. – Sethmr
@Sethmr 질문을 읽거나 태그를 잘 살펴보십시오. –