小编Bry*_*ore的帖子

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
Run Code Online (Sandbox Code Playgroud)

另一种解决方案是(从这个博客获得):

@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];

        // …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c interface-builder nstextfieldcell

9
推荐指数
1
解决办法
8020
查看次数

os.kill没有引发OSError,但是我没有看到给定的pid正在运行

在我的ubuntu服务器上,我运行以下命令:

python -c 'import os; os.kill(5555, 0)'
Run Code Online (Sandbox Code Playgroud)

这样做是为了让我可以看到pid 5555是否正在运行.根据我的理解,如果pid没有运行,这应该引发一个OSError.这不会给我带来OSError,这意味着它应该是一个正在运行的进程.但是,当我跑:

ps aux | grep 5555
Run Code Online (Sandbox Code Playgroud)

我看到没有进程与该pid一起运行.这也发生在该一般范围内的其他几个pid上,但不会发生555或55555.

有没有人知道为什么os.kill不会像预期的那样引发OSError?

注意:这是在python 2.5.1下运行的.

python ubuntu pid

4
推荐指数
1
解决办法
2115
查看次数

NS String比较因stringWithFormat而失败

我有两个具有相同值的NSStrings

这对我失败了:

if (button.controlName == controlName) {
        return button;
    }
Run Code Online (Sandbox Code Playgroud)

这工作:

if ([button.controlName compare: controlName] == NSOrderedSame) {
        return button;
    }
Run Code Online (Sandbox Code Playgroud)

这是在目标c中比较字符串的方式吗?或者第一个声明是否也有效?为什么第一个陈述失败了?我知道它适用于其他字符串.

它不起作用的字符串初始化如下:

button.controlName = [NSString stringWithFormat:@"controlName%d", i]
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsstring

2
推荐指数
1
解决办法
588
查看次数

C#string解析为变量类型

我想轻松地将一个字符串解析成一个类型,但是我不想为每个类型编写包装器代码,我只是希望能够执行"1234".Parse()之类的操作并让它返回1234.应该适用于任何具有解析功能的类型.

c#

1
推荐指数
3
解决办法
6266
查看次数