• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Custom Shaped Buttons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom Shaped Buttons


  • Subject: Re: Custom Shaped Buttons
  • From: David Adalsteinsson <email@hidden>
  • Date: Thu, 20 Mar 2008 09:57:30 -0400

I would recommend that you create your own button type, not based on NSButton, and handle everything in the mouseDown event.

while (1) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate date]];
theEvent = [theWindow nextEventMatchingMask:NSAnyEventMask
untilDate :[NSDate dateWithTimeIntervalSinceNow:0.02]
inMode:NSEventTrackingRunLoopMode
dequeue:YES ];


if ([theEvent type]==NSLeftMouseDragged) {
cursorLocationInView = [self convertPoint: [theEvent locationInWindow] fromView:nil];


// Do your hit testing, for example using a NSBezierPath object, and then change the drawing style.
// Might need to manually call [self display] if the state changes (but I don't think you do, haven't checked).
}


                  if ([theEvent type]==NSLeftMouseUp) {
                           // The drag stopped
                           break;
                  }
         }


If you implement the same methods as NSButton does, you should be able to treat them exactly the same.
The drawRect: method would draw the image that corresponds to the shape. It is very easy to get images from the bundle based on names.


On Mar 20, 2008, at 8:43 AM, ADIL SALEEM wrote:

Hi,

I need guidance for a problem. I want to make custom
shaped buttons (based on images) in my GUI.

By assigning image and alternate image in IB it
displays the image but the shape of the button is not
exactly as the image. I want to make the button of
exact shape as that of the image.

For that i am trying to subclass NSButton. I have
created the subclass and assigned it to my buttons,
but i have no idea what functions to
implement/overwrite in the subclass to change the
shape of the button and assign the image as the button
shape.


Also please tell me that is this the right way (subclassing NSButton) to do what i am trying to do ?

Thank you



____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Custom Shaped Buttons (From: ADIL SALEEM <email@hidden>)

  • Prev by Date: Re: memcpy strange behavior
  • Next by Date: Re: Setting Web Proxy programmatically
  • Previous by thread: Re: Custom Shaped Buttons
  • Next by thread: Re: Custom Shaped Buttons
  • Index(es):
    • Date
    • Thread