- (voID)drawString:(Nsstring *)string inRect:(NSRect)rect { static NSDictionary *att = nil; if (!att) { NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutablecopy]; [style setlineBreakMode:NSlineBreakByTruncatingTail]; [style setAlignment:NSCenterTextAlignment]; att = [[NSDictionary alloc] initWithObjectsAndKeys: style,NSParagraphStyleAttributename,[NScolor whitecolor],NSForegroundcolorAttributename,[NSFont FontWithname:@"Helvetica" size:12],NSFontAttributename,nil]; [style release]; } NSRect TitlebarRect = NSMakeRect(rect.origin.x+20,rect.origin.y-4,rect.size.wIDth,rect.size.height); [string drawInRect:TitlebarRect withAttributes:att];}- (voID)drawRect:(NSRect)dirtyRect{ NSRect windowFrame = [NSWindow frameRectForContentRect:[[[self window] contentVIEw] bounds] styleMask:[[self window] styleMask]]; NSRect contentBounds = [[[self window] contentVIEw] bounds]; NSRect TitlebarRect = NSMakeRect(0,self.bounds.size.wIDth,windowFrame.size.height - contentBounds.size.height); TitlebarRect.origin.y = self.bounds.size.height - TitlebarRect.size.height; NSRect topHalf,bottomHalf; NSdivIDeRect(TitlebarRect,&topHalf,&bottomHalf,floor(TitlebarRect.size.height / 2.0),NSMaxYEdge); NSBezIErPath * path = [NSBezIErPath bezIErPathWithRoundedRect:self.bounds xRadius:4.0 yRadius:4.0]; [[NSBezIErPath bezIErPathWithRect:TitlebarRect] addClip]; NSGradIEnt * gradIEnt1 = [[[NSGradIEnt alloc] initWithStartingcolor:[NScolor colorWithCalibrateDWhite:0.0 Alpha:1.0] endingcolor:[NScolor colorWithCalibrateDWhite:1 Alpha:1.0]] autorelease]; NSGradIEnt * gradIEnt2 = [[[NSGradIEnt alloc] initWithStartingcolor:[NScolor colorWithCalibrateDWhite:1 Alpha:1.0] endingcolor:[NScolor colorWithCalibrateDWhite:0 Alpha:1.0]] autorelease]; [path addClip];// [[NScolor colorWithCalibrateDWhite:0.00 Alpha:1.0] set];// [path fill]; [gradIEnt1 drawInRect:topHalf angle:270.0]; [gradIEnt2 drawInRect:bottomHalf angle:270.0]; [[NScolor blackcolor] set]; NSRectFill(NSMakeRect(0,-4,1.0)); [self drawString:@"My Title" inRect:TitlebarRect];}
在appDelegate中导入MyTitleVIEw类并添加以下代码
- (voID)applicationDIDFinishLaunching:(NSNotification *)aNotification{ NSRect boundsRect = [[[_window contentVIEw] supervIEw] bounds]; BlackTitlebarVIEw * TitlevIEw = [[BlackTitlebarVIEw alloc] initWithFrame:boundsRect]; [TitlevIEw setautoresizingMask:(NSVIEwWIDthSizable | NSVIEwHeightSizable)]; [[[_window contentVIEw] supervIEw] addSubvIEw:TitlevIEw @R_403_4612@ed:NSWindowBelow relativeTo:[[[[_window contentVIEw] supervIEw] subvIEws] objectAtIndex:0]];}总结
以上是内存溢出为你收集整理的如何在OSX中更改NSWindow标题栏的颜色全部内容,希望文章能够帮你解决如何在OSX中更改NSWindow标题栏的颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)