- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
NSGradient *backgroundGradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:239.0/255.0 green:239.0/255.0 blue:239.0/255.0 alpha:1.0] endingColor:[NSColor colorWithDeviceRed:239.0/255.0 green:239.0/255.0 blue:239.0/255.0 alpha:1.0]];
[backgroundGradient drawInRect:[self bounds] angle:90.0];
// Drawing code here.
}
本文介绍了一个使用NSGradient在Objective-C中为视图绘制背景的方法。通过创建一个从左到右颜色渐变的背景,实现了视图的美化效果。代码示例展示了如何在drawRect方法中调用NSGradient来完成绘制。
332

被折叠的 条评论
为什么被折叠?



