2020年2月

NSImageView图像填充模式

NSImageView图像填充模式

可以使用这个:图像将强制填充视图大小

(Aspect Fill)

imageView.imageScaling = .scaleAxesIndependently

(Aspect Fit)

imageView.imageScaling = .scaleProportionallyUpOrDown

(中心顶部)

imageView.imageScaling = .scaleProportionallyDown

您可能会发现子类更容易 NSView 并提供一个 CALayer 方面为您填充的内容。以下是 initNSView 子类的可能外观。

- (id)initWithFrame:(NSRect)frame andImage:(NSImage*)image {
  self = [super initWithFrame:frame];
  if (self) {
    self.layer = [[CALayer alloc] init];
    self.layer.contentsGravity = kCAGravityResizeAspectFill;
    self.layer.contents = image;
    self.wantsLayer = YES;
  }
  return self;
}

请注意,设置图层的顺序,然后设置 wantsLayer 非常重要(如果先设置wantsLayer,则会获得默认的背衬层)。

您可以使用一种 setImage 方法来简单地更新图层的内容。

Link:(NSImageView图像方面填充?)[https://xbuba.com/questions/23002653]

通过命令行安装iPhone模拟器

查看所有模拟器

xcrun instruments -s

通过以上命令,可以看到系统有以下模拟器:

iPhone 8 (11.2) [39E670F7-F9B0-4A1F-92E7-202EED62E66A] (Simulator)
iPhone 8 (11.2) + Apple Watch Series 3 - 38mm (4.2) [02C9E3B3-9846-4AD0-9890-B2B840811BC9] (Simulator)
iPhone 8 Plus (11.2) [18B8751C-097C-427C-9DB8-BF59FB3C1D7E] (Simulator)
iPhone 8 Plus (11.2) + Apple Watch Series 3 - 42mm (4.2) [E381F8A1-54E9-4428-BE4A-7011902C5D69] (Simulator)
iPhone SE (11.2) [D8ACFB1F-6678-4014-8993-72050939481D] (Simulator)
iPhone X (11.2) [1346D0CB-C0A7-40F9-BB8B-C095B736C696] (Simulator)

打开指定模拟器

xcrun instruments -w "iPhone 8 (11.2)"

安装指定APP

xcrun simctl install booted <app路径>

运行指定的app (com.example.app)

xcrun simctl launch booted <app identifier>

卸载指定的应用

xcrun simctl uninstall booted <app identifier>

Link: 从命令行启动Xcode模拟器