改变视图的背景颜色似乎很难?

时间:2015-10-22 14:05:51

标签: objective-c xcode macos cocoa view

我想更改视图控制器中视图的背景颜色。选择视图并打开属性检查器并没有显示出那么多。这里应该有一个背景选项。

enter image description here

尝试在onCreate中使用ActivityCompat.postponeEnterTransition(this); Picasso.with(this.getApplicationContext()) .load("https://goo.gl/oiyTor") .noFade() .fit() .centerInside() .error(R.drawable.user_placeholder_error) .into(((ImageView) findViewById(R.id.game_view_image)), new Callback() { @Override public void onSuccess() { ActivityCompat.startPostponedEnterTransition(targetActivity); } @Override public void onError() { ActivityCompat.startPostponedEnterTransition(targetActivity); } }); 对其进行编码,但也没有工作,没有NSView的对象。

我做错了什么?我读到编码问题可能与更新版本的Xcode有关。 coding issue

2 个答案:

答案 0 :(得分:1)

这已经受到质疑和回答了 Best way to change the background color for an NSView

这是OS X的代码

[self.view setWantsLayer:YES];
[self.view.layer setBackgroundColor:[[NSColor whiteColor] CGColor]];

答案 1 :(得分:0)

你使用的xcode版本是什么?这是我使用7.1版(7B91b)中的属性检查器更改背景颜色的方法 enter image description here