के साथ NSSecureTextField में लंबवत रूप से केंद्र टेक्स्ट मैं अपने एनएसटीक्स्टफिल्ड्स में लंबवत रूप से टेक्स्ट टेक्स्ट करने की कोशिश कर रहा हूं, लेकिन उनमें से एक पासवर्ड के लिए है, इसलिए यह एक NSSecureTextField है। मैं इसे की क्लास निम्नलिखित कार्यान्वयन के साथ MDVerticallyCenteredSecureTextFieldCell
होने के लिए निर्धारित किया है:उप-वर्गीकरण
- (NSRect)adjustedFrameToVerticallyCenterText:(NSRect)frame {
// super would normally draw text at the top of the cell
NSInteger offset = floor((NSHeight(frame) -
([[self font] ascender] - [[self font] descender]))/2);
return NSInsetRect(frame, 0.0, offset+10);
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView
editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event {
[super editWithFrame:[self adjustedFrameToVerticallyCenterText:aRect]
inView:controlView editor:editor delegate:delegate event:event];
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView
editor:(NSText *)editor delegate:(id)delegate
start:(NSInteger)start length:(NSInteger)length {
[super selectWithFrame:[self adjustedFrameToVerticallyCenterText:aRect]
inView:controlView editor:editor delegate:delegate
start:start length:length];
}
- (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)view {
[super drawInteriorWithFrame:
[self adjustedFrameToVerticallyCenterText:frame] inView:view];
}
-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
[super drawWithFrame:cellFrame inView:controlView];
}
ऐसा ही एक उपवर्ग पहले से ही नियमित रूप से NSTextFieldCell
रों के लिए काम कर रहा है, तो बस इस के संस्करणों सुरक्षित नहीं। ऐसा लगता है जैसे ऐप्पल ने इन विधियों को ओवरराइड होने से सुरक्षित रखा है।
अब पासवर्ड क्षेत्र केवल एक गलत संरेखित है:
किसी को भी सुझाव है कि एक तरह से NSSecureTextFieldCell
उपवर्ग के तरीकों के नाम से जाना मिल सकता है या किसी अन्य तरीके से खड़ी पाठ क्षेत्र केंद्रित करने के लिए?
धन्यवाद, यह काम किया। – jrc
यह मेरे लिए भी काम किया। धन्यवाद! – Tommy