Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a custom view #2

Open
Phildecarry opened this issue Jan 28, 2024 · 1 comment
Open

create a custom view #2

Phildecarry opened this issue Jan 28, 2024 · 1 comment

Comments

@Phildecarry
Copy link

i dragded an image view in the Xcode Xib file then with the Inspector i made it a subclass of NSView and named it" Heart" . Then i created a new swift file called "Heart" that i inserted with the other project files.

Inside the Heart.swift there is:

import Cocoa

class coeur: NSView
{

 ​ ​o​v​e​r​r​i​d​e​ ​f​u​n​c​ ​d​r​a​w​R​e​c​t​(​d​i​r​t​y​R​e​c​t​:​ ​N​S​R​e​c​t​)​ ​{                                     
​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​l​e​t​ ​b​a​c​k​g​r​o​u​n​d​C​o​l​o​r​ ​=​ ​N​S​C​o​l​o​r​.​l​i​g​h​t​G​r​a​y​C​o​l​o​r​(​)
​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​b​a​c​k​g​r​o​u​n​d​C​o​l​o​r​.​s​e​t​(​)
​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​N​S​B​e​z​i​e​r​P​a​t​h​.​f​i​l​l​R​e​c​t​(​b​o​u​n​d​s​)
​ ​ ​ ​​ ​ ​ ​}

}
When running i have compiler error

class coeur: NSView 1. In declaration of 'coeur'
{

 ​ ​o​v​e​r​r​i​d​e​ ​f​u​n​c​ ​d​r​a​w​R​e​c​t​(​d​i​r​t​y​R​e​c​t​:​ ​N​S​R​e​c​t​)​ ​{                  Expected declaration
​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​l​e​t​ ​b​a​c​k​g​r​o​u​n​d​C​o​l​o​r​ ​=​ ​N​S​C​o​l​o​r​.​l​i​g​h​t​G​r​a​y​C​o​l​o​r​(​)
​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​b​a​c​k​g​r​o​u​n​d​C​o​l​o​r​.​s​e​t​(​)
​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​N​S​B​e​z​i​e​r​P​a​t​h​.​f​i​l​l​R​e​c​t​(​b​o​u​n​d​s​)
​ ​ ​ ​​ ​ ​ ​}

}

if i run the empty class no error:
class coeur: NSView
{

​ ​​ ​ ​ ​}

i changed the function drawRect with Rect and tried many changes inside the func : it s not the probleme.
Something wrong with the declaration of the class
Wrote on swift 4 Xcode 9. My whole project is an NSDocument type.
i am not a software engineer or pro develeppoer or student , any help is welcomed. thanks a lot

@Phildecarry
Copy link
Author

my "image view" is a custom view dragged on the canvas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant