nsview

WebView Insert / Modify Content dynamically

末鹿安然 提交于 2019-11-29 23:27:52
问题 In my application, i am using WebView to display the content, Now is it possible to modify the content dynamically, the requirement is something like this, i will get info from network and depending upon them i need to set the style/font/attribute or probably i need to append the new text when the connected device is not responding, So far i am using following code, -(void)modifyString:(NSString *)string{ [sourceString stringByAppendingString:errorString :string] } -(void)reloadPage{ [

Drawing selection box (rubberbanding, marching ants) in Cocoa, ObjectiveC

て烟熏妆下的殇ゞ 提交于 2019-11-29 21:57:43
I've currently implemented a simple selection box using mouse events and redrawing a rectangle on mouse drag. Here's my code: -(void)drawRect:(NSRect)dirtyRect { if (!NSEqualRects(self.draggingBox, NSZeroRect)) { [[NSColor grayColor] setStroke]; [[NSBezierPath bezierPathWithRect:self.draggingBox] stroke]; } } #pragma mark Mouse Events - (void)mouseDown:(NSEvent *)theEvent { NSPoint pointInView = [self convertPoint:[theEvent locationInWindow] fromView:nil]; self.draggingBox = NSMakeRect(pointInView.x, pointInView.y, 0, 0); [self setNeedsDisplay:YES]; } - (void)mouseDragged:(NSEvent *)theEvent {

Make NSView in NSPanel first responder without key window status

。_饼干妹妹 提交于 2019-11-29 21:42:02
问题 Is it possible to give an NSView inside an NSPanel first responder status without giving the NSPanel key window status (making the main application window resign key)? Thanks. 回答1: Well, I ended up figuring this one out, but it took a lot of research so I'll post the details here in case anyone else runs into the same problem. First of all, a few basics: It's impossible to have 2 windows actually be key at the same time It's possible to fake a window into thinking it's key by overriding

NSWindow with round corners and shadow

前提是你 提交于 2019-11-29 20:39:09
I'm trying to crate a NSWindow without title bar ( NSBorderlessWindowMask ) with round corners and a shadow, similar to the below "Welcome to Xcode" window. I make a subclass of NSWindow : @implementation FlatWindow - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:flag]; if ( self ) { [self setOpaque:NO]; [self setBackgroundColor:[NSColor clearColor]]; [self setMovableByWindowBackground:TRUE]; [self

How to set NSView size programmatically?

感情迁移 提交于 2019-11-29 13:41:07
问题 How do you set the size of NSView programmically e.g. -(void)awakeFromNib { self.frame.size.width = 1280; // Does nothing... self.frame.size.height = 800; // ...neither does this. ... The size setup in the nib (of Mac OSX) works OK, but I want to do it in code. 回答1: When you call self.frame, it returns the data in the frame, and not a pointer. Therefore, any change in the result is not reflected in the view. In order to change the view, you have to set the new frame after you make changes: -

Converting an NSPoint from window coordinates to view coordinates

主宰稳场 提交于 2019-11-29 11:53:24
问题 My application has a custom view that displays a timeline of events. This view is wrapped in an NSScrollView to support horizontal scrolling of the timeline. Using notifications, I've implemented a mechanism that should show another custom view which displays detail information about an event when the user clicks that event in the timeline. Below is the code that handles the event when it is received by the timeline: NSEvent *anEvent = [aNotification object]; NSPoint aLocationInSelf = [self

Backward compatibility of Xcode OSX

喜欢而已 提交于 2019-11-29 11:47:28
How to use features such as viewDidLoad or appDidBecomeActive in Xcode 4.6.1 for OSX 10.8, which are available only for OSX 10.10 and above. Please suggest the alternative ways to use these functions. To expand on Ken Thomas's comment; this is the code that I use: - (void)loadView { [super loadView]; // if we're running on 10.8 or older… if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_8) { [self viewDidLoad]; // call viewDidLoad (added in 10.9) } } // // This will be called by loadView pre-10.9; directly otherwise // - (void)viewDidLoad { // --- YOUR CODE HERE --- } // viewDidLoad I'd

Get Image from CALayer or NSView (swift 3)

扶醉桌前 提交于 2019-11-29 10:09:52
I was looking for a way to render CALayer or NSView and get NSImage back. I have a custom class which is a subclass of NSView. In the beginning I simply make a gradient layer to cover all NSView. class ContentView: NSView { override func draw(_ dirtyRect: NSRect) { fillGradientLayer() } func fillGradientLayer() { gradientLayer = CAGradientLayer() gradientLayer.colors = [#colorLiteral(red: 0, green: 0.9909763549, blue: 0.7570167824, alpha: 1),#colorLiteral(red: 0, green: 0.4772562545, blue: 1, alpha: 1)].map({return $0.cgColor}) gradientLayer.startPoint = CGPoint(x: 0, y: 0.5) gradientLayer

How to disable user interaction in a custom View

£可爱£侵袭症+ 提交于 2019-11-29 09:22:22
I have a custom View NSView and I want to disable userinteraction, but I'm not sure how to do this. My idea was: [myView setEnabled:NO]; but it's wrong and doesn't work. How can I make it so that, it's just visible for the user, and nothing else? NSView doesn't have either setEnabled: or setIgnoresMouseEvents: Implement the hitTest: method to return nil . From here : // // NSView-DisableSubsAdditions.m // Can Combine Icons // // Created by David Remahl on Tue Dec 25 2001. // Copyright (c) 2001 Infinity-to-the-Power-of-Infinity. All rights reserved. // #import "NSView-DisableSubsAdditions.h"

Setting backgroundColor of custom NSView

你。 提交于 2019-11-29 00:23:50
问题 What is the process of drawing to NSView using storyboards for osx? I have added a NSView to the NSViewController. Then, I added a few constraints and an outlet. Next, I added some code to change the color: import Cocoa class ViewController: NSViewController { @IBOutlet var box: NSView! override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear() { box.layer?.backgroundColor = NSColor.blueColor().CGColor //box.layer?.setNeedsDisplay() } override var representedObject: