Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "BBWeeAppController-Protocol.h"
- #import <Twitter/Twitter.h>
- /***
- TUTORIAL BY ANDY IBANEZ (@Leonnears).
- This is the tutorial I wrote about writing notification center widgets for iOS. You can find it on my tumblr blog (leonnears.tumblr.com).
- You can also follow me on Twitter (@Twitter) to receive updates when I write anything in my new blog, including when I post new tutorials and so on. I don't only tweet programming related stuff so don't follow me if you expect to only see programming or tech related stuff. ;)
- */
- static NSBundle *_iNotitweetWeeAppBundle = nil;
- @interface iNotitweetController: NSObject <BBWeeAppController> {
- UIView *_view;
- UIImageView *_backgroundView;
- }
- @property (nonatomic, retain) UIView *view;
- @end
- @implementation iNotitweetController
- @synthesize view = _view;
- + (void)initialize {
- _iNotitweetWeeAppBundle = [[NSBundle bundleForClass:[self class]] retain];
- }
- - (id)init {
- if((self = [super init]) != nil) {
- } return self;
- }
- - (void)dealloc {
- [_view release];
- [_backgroundView release];
- [super dealloc];
- }
- - (void)loadFullView {
- // Add subviews to _backgroundView (or _view) here.
- UIButton *tweet = [UIButton buttonWithType:UIButtonTypeCustom];
- [tweet setBackgroundImage:[UIImage imageWithContentsOfFile:[_iNotitweetWeeAppBundle pathForResource:@"tweet" ofType:@"png"]] forState:UIControlStateNormal];
- tweet.frame = CGRectMake(2, 0, 79, 33);
- [tweet addTarget:self action:@selector(composeTweet) forControlEvents:UIControlEventTouchDown];
- [_view addSubview:tweet];
- }
- -(void)composeTweet {
- TWTweetComposeViewController *twtComposer = [[TWTweetComposeViewController alloc] init];
- UIViewController *someVc = [[UIViewController alloc] init];
- twtComposer.completionHandler = ^(TWTweetComposeViewControllerResult result)
- {
- if(result == TWTweetComposeViewControllerResultCancelled)
- {
- [someVc dismissModalViewControllerAnimated:YES];
- }
- };
- someVc.view = _view;
- [someVc presentModalViewController:twtComposer animated:YES];
- [someVc release];
- [twtComposer release];
- }
- - (void)loadPlaceholderView {
- // This should only be a placeholder - it should not connect to any servers or perform any intense
- // data loading operations.
- //
- // All widgets are 316 points wide. Image size calculations match those of the Stocks widget.
- _view = [[UIView alloc] initWithFrame:(CGRect){CGPointZero, {316.f, 33.f}}];
- _view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- UIImage *bgImg = [UIImage imageWithContentsOfFile:@"/System/Library/WeeAppPlugins/StocksWeeApp.bundle/WeeAppBackground.png"];
- UIImage *stretchableBgImg = [bgImg stretchableImageWithLeftCapWidth:floorf(bgImg.size.width / 2.f) topCapHeight:floorf(bgImg.size.height / 2.f)];
- _backgroundView = [[UIImageView alloc] initWithImage:stretchableBgImg];
- _backgroundView.frame = CGRectInset(_view.bounds, 2.f, 0.f);
- _backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [_view addSubview:_backgroundView];
- }
- - (void)unloadView {
- [_view release];
- _view = nil;
- [_backgroundView release];
- _backgroundView = nil;
- // Destroy any additional subviews you added here. Don't waste memory :(.
- }
- - (float)viewHeight {
- return 71.f;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement