小编Elf*_*ros的帖子

如何在视图中居中NSTextField

我在一个带有文本"__DRAG_AND_DROP_YOUR_MEDIA_HERE"的视图中以IB为中心的NSTextField(标签).在我的控制器中使用NSLocalizedString来翻译文本:

English.lproj/Localizable.strings:

"__DRAG_AND_DROP_YOUR_MEDIA_HERE" = "Drag & Drop your media here"
Run Code Online (Sandbox Code Playgroud)

French.lproj/Localizable.strings:

"__DRAG_AND_DROP_YOUR_MEDIA_HERE" = "Déposer vos média ici"
Run Code Online (Sandbox Code Playgroud)

只有初始文本"__DRAG_AND_DROP_YOUR_MEDIA_HERE"在视图中居中.翻译后的文本不是中心(取决于长度).所有翻译的文本都以与原始文本相同的横坐标开始.我该如何解决这个问题?

PS:我不想玩setFrame,高度,宽度只是为了这样一个简单的点.我想还有另一种方法可以做到这一点.

谢谢.

xcode cocoa objective-c interface-builder nstextfield

6
推荐指数
1
解决办法
6862
查看次数

yum error - centos 7.1 x86_64

我在专用服务器上遇到yum命令的问题(由OVH托管):

[root@mail-server ~]# yum clean all
[root@mail-server ~]# yum update
Modules complémentaires chargés : fastestmirror


 One of the configured repositories failed (Inconnu),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This …
Run Code Online (Sandbox Code Playgroud)

dns centos yum

6
推荐指数
2
解决办法
3万
查看次数

NSLocalizedString不起作用

我想在我的应用程序中使用NSLocalizedString,但它总是失败.我做的是:

  • 在项目属性中定义3个本地化(见下面的截图)
  • 创建一个新文件:Resource Strings File
  • 如果file.strings在那里,请检查应用程序包

然后我使用NSLocalizedStrings如下,但它不起作用!

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    NSString *v1 = NSLocalizedString(@"MyWindow", nil);

    //NSString *v1 = [[NSBundle mainBundle] localizedStringForKey:(@"MyWindow") value:@"" table:nil];
    [label setStringValue:v1];
}
Run Code Online (Sandbox Code Playgroud)

在我的3 .strings文件中,我定义了下面的键/值:"MyWindow"="Ma Fenetre";

通常,我的标签应显示"Ma Fenetre"而不是"MyWindows"您可以在此处下载示例项目并告诉我问题在哪里.

Bellow我的应用包中的Resources文件夹的内容:

DerivedData om$ find test/Build/Products/Debug/test.app/Contents/Resources/
test/Build/Products/Debug/test.app/Contents/Resources/
test/Build/Products/Debug/test.app/Contents/Resources//de.lproj
test/Build/Products/Debug/test.app/Contents/Resources//de.lproj/File.strings
test/Build/Products/Debug/test.app/Contents/Resources//en.lproj
test/Build/Products/Debug/test.app/Contents/Resources//en.lproj/File.strings
test/Build/Products/Debug/test.app/Contents/Resources//fr.lproj
test/Build/Products/Debug/test.app/Contents/Resources//fr.lproj/File.strings
test/Build/Products/Debug/test.app/Contents/Resources//MainMenu.nib
Run Code Online (Sandbox Code Playgroud)

谢谢Elfoiros

xcode cocoa-touch localization objective-c ios

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

NSCollectionView如何滚动到所选项目

我以编程方式在我的NSCollectionView中选择一个项目.项目按预期选择,但视图不会自动滚动到此项目.

[collectionView setSelectionIndexes:[NSIndexSet indexSetWithIndex:compt]];
Run Code Online (Sandbox Code Playgroud)

如何滚动到所选项目?

cocoa objective-c nscollectionview nsscrollview

3
推荐指数
2
解决办法
2838
查看次数

如何更改自定义NSTextfield的drawRect中的文本颜色

我使用NSTextfield的自己的类OMNTextfield子类来显示文本,并在文本长度大于控件宽度时为文本设置动画.

该文字在iTunes中像歌曲标题一样动画.它就像一个魅力!

现在我想更改文本的颜色和文本对齐方式.我已经搜索了一会儿setTextcolor,setAlignment,viewWillDraw,cellClass,...但没有任何工作=>我的文字仍然是黑色的!

你可以在这里找到完整的代码(Xcode项目)

我的问题:如何更改NSTextfield子类中的文本颜色/对齐方式?

Acoording 这个职位代码波纹管应该工作,但它不会!

-(void)viewWillDraw { // or whatever is the Appkit equivalent
      [super setTextColor:[NSColor redColor]];
}
Run Code Online (Sandbox Code Playgroud)

完整代码:

//
//  OMNTextField.h


#import <Cocoa/Cocoa.h>

@interface OMNTextField : NSTextField {
    NSTimer * scroller;
    NSPoint point;
    NSString * text;
    NSTimeInterval speed;
    CGFloat stringWidth;
}

- (void) setText:(NSString *)newText;

@property (nonatomic, copy) NSString * text;
@property (nonatomic) NSTimeInterval speed;

@end

//
//  OMNTextField.m

#import "OMNTextField.h"

@implementation OMNTextField

@synthesize text;
@synthesize speed;


- (void) dealloc {
    [text release];
    [scroller invalidate];
    [super …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c interface-builder nstextfield

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