当我创建NSComboBox并将控件大小设置为较小时,焦点环未正确对齐。 我在xcode界面注意到了同样的问题(cfr。截图)。
欢迎您的帮助。
答案 0 :(得分:3)
我今天在bugreport.apple.com上将此报告为雷达#20852031
我的解决方法是子类NSComboBoxCell:
- (void)drawFocusRingMaskWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSRect focusRect = cellFrame;
focusRect.origin.y += 1.0f;
focusRect.size.width -= 3.0f;
focusRect.size.height -= 5.0f;
// NSBezierPath *focusPath = [NSBezierPath bezierPathWithRoundedRect:focusRect
// xRadius:2.0f
// yRadius:2.0f];
NSBezierPath *focusPath = [NSBezierPath bezierPath];
CGFloat leftRadius = 2.0f;
CGFloat rightRadius = 5.0f;
[focusPath moveToPoint:NSMakePoint(focusRect.origin.x + leftRadius, focusRect.origin.y)];
[focusPath lineToPoint:NSMakePoint(focusRect.origin.x + focusRect.size.width - rightRadius, focusRect.origin.y)];
[focusPath curveToPoint:NSMakePoint(focusRect.origin.x + focusRect.size.width, focusRect.origin.y + rightRadius)
controlPoint1:NSMakePoint(focusRect.origin.x + focusRect.size.width, focusRect.origin.y)
controlPoint2:NSMakePoint(focusRect.origin.x + focusRect.size.width, focusRect.origin.y)];
[focusPath lineToPoint:NSMakePoint(focusRect.origin.x + focusRect.size.width, focusRect.origin.y + focusRect.size.height - rightRadius)];
[focusPath curveToPoint:NSMakePoint(focusRect.origin.x + focusRect.size.width - rightRadius, focusRect.origin.y + focusRect.size.height)
controlPoint1:NSMakePoint(focusRect.origin.x + focusRect.size.width, focusRect.origin.y + focusRect.size.height)
controlPoint2:NSMakePoint(focusRect.origin.x + focusRect.size.width, focusRect.origin.y + focusRect.size.height)];
[focusPath lineToPoint:NSMakePoint(focusRect.origin.x + leftRadius, focusRect.origin.y + focusRect.size.height)];
[focusPath curveToPoint:NSMakePoint(focusRect.origin.x, focusRect.origin.y + focusRect.size.height - leftRadius)
controlPoint1:NSMakePoint(focusRect.origin.x, focusRect.origin.y + focusRect.size.height)
controlPoint2:NSMakePoint(focusRect.origin.x, focusRect.origin.y + focusRect.size.height)];
[focusPath lineToPoint:NSMakePoint(focusRect.origin.x, focusRect.origin.y + leftRadius)];
[focusPath curveToPoint:NSMakePoint(focusRect.origin.x + leftRadius, focusRect.origin.y)
controlPoint1:NSMakePoint(focusRect.origin.x, focusRect.origin.y)
controlPoint2:NSMakePoint(focusRect.origin.x, focusRect.origin.y)];
[NSGraphicsContext saveGraphicsState];
{
[focusPath fill];
}
[NSGraphicsContext restoreGraphicsState];
}