मेरे पास एक NSTextFieldCell है जिसे मैं मध्यम लंबवत संरेखण के साथ प्रदर्शित करना चाहता हूं। यहां एक पुराने प्रश्न और ब्लॉग एंट्री के लिए धन्यवाद, मेरे पास दो कामकाजी समाधान हैं।NSTextFieldCell लंबवत संरेखण, समाधान क्षैतिज संरेखण को स्क्वैश करने लगते हैं
हालांकि, दोनों समाधान सेल को सही गठबंधन के रूप में सेट करने की मेरी क्षमता को स्क्वैश करने लगते हैं। क्या कोई मुझे इन समाधानों में से किसी एक को संरेखण के दोनों रूपों का समर्थन करने में मदद कर सकता है?
@implementation MiddleAlignedTextFieldCell
- (NSRect)titleRectForBounds:(NSRect)theRect {
NSRect titleFrame = [super titleRectForBounds:theRect];
NSSize titleSize = [[self attributedStringValue] size];
titleFrame.origin.y = theRect.origin.y - .5 + (theRect.size.height - titleSize.height)/2.0;
return titleFrame;
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSRect titleRect = [self titleRectForBounds:cellFrame];
[[self attributedStringValue] drawInRect:titleRect];
}
@end
वैकल्पिक समाधान (this blog से प्राप्त) है::
@implementation RSVerticallyCenteredTextFieldCell
- (NSRect)drawingRectForBounds:(NSRect)theRect
{
NSRect newRect = [super drawingRectForBounds:theRect];
if (mIsEditingOrSelecting == NO)
{
// Get our ideal size for current text
NSSize textSize = [self cellSizeForBounds:theRect];
// Center that in the proposed rect
float heightDelta = newRect.size.height - textSize.height;
if (heightDelta > 0)
{
newRect.size.height -= heightDelta;
newRect.origin.y += (heightDelta/2);
}
}
return newRect;
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart length:(int)selLength
{
aRect = [self drawingRectForBounds:aRect];
mIsEditingOrSelecting = YES;
[super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
mIsEditingOrSelecting = NO;
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
aRect = [self drawingRectForBounds:aRect];
mIsEditingOrSelecting = YES;
[super editWithFrame:aRect inView:controlView editor:textObj delegate:anObject event:theEvent];
mIsEditingOrSelecting = NO;
}
@end
मुझे प्रस्तुति के उस हिस्से में मेरी डेटा परत के साथ जोड़े की आवश्यकता है, और ईमानदारी से मुझे यकीन नहीं है कि मुझे यह पसंद है। इसे आईबी में प्रस्तुत विकल्पों का सम्मान करना चाहिए, लेकिन कुछ कारणों से यह नहीं है (उस मामले के लिए लंबवत संरेखण भी आईबी में एक विकल्प होना चाहिए)। –
मुझे यकीन नहीं है कि यह आपके मॉडल परत से कुछ के लिए NSTextFieldCell की स्ट्रिंग को सेट करने से कहीं अधिक कैसे मिश्रण कर रहा है।:-) संरेखण (और फ़ॉन्ट, और रंग, और आकार, ...) यह सब का हिस्सा है। हालांकि, मैं सहमत हूं कि लंबवत संरेखण एक विकल्प होना चाहिए - एक वृद्धि रिपोर्ट दर्ज करें। चूंकि यह उपलब्ध नहीं है, इसलिए आपको ड्राइंग कोड में इसके लिए खाता लेना होगा। –
एर, यह "वृद्धि अनुरोध" है। लिंक: http://bugreporter.apple.com –