Objective C Objective c date:NSString Date

NSDate* date = [NSDate date];

        //Create the dateformatter object

        NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];

        //Set the required date format

        [formatter setDateFormat:@"yyyy-MM-dd"];

        //Get the string date

        NSString* str = [formatter stringFromDate:date];

        //Display on the console

        NSLog(str);

        //Set in the lable

        [dateLabel setText:str];

Objective C 异步图像代码

[[AsyncImageCache shared] loadImageForURL:updateAnnotation.profileImageURL delegate:self];


//---------------------------------------------------------------------
// AsyncImageCache Delegate
//---------------------------------------------------------------------

- (void)asyncImageCacheLoadedImage:(UIImage *)image forURL:(NSString *)url
{
	// just in case
	[twitterUserIcon release];
	twitterUserIcon = nil;

	// remember this image, if it corresponds to the expected URL
	UpdateAnnotation *updateAnnotation = (UpdateAnnotation *) self.annotation;
	if (image != nil && [url isEqualToString:updateAnnotation.profileImageURL])
	{
		twitterUserIcon = [image retain];
		[self fadeInNewUserIcon];
	}

	// force full redraw
	[self setNeedsDisplay];
}

Objective C 如何使用Cocoa(Objective C) - macosx.com启动URL

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.ithinksw.com/"]];

Objective C 使用Bombax发送HTML消息

#import "MyHandler.h"

@implementation MyHandler

- (id)renderWithTransport:(BxTransport *)transport {
    NSString *htmlMessage = @"<html><body>This is an <em>HTML</em> message.<br /> — <a href='http://www.bombaxtic.com'>www.bombaxtic.com</a></body></html>";
    [[BxMailer systemMailer] sendMessage:htmlMessage
                                 subject:@"Html Message"
                                      to:@"dominic@bombaxtic.com"
                                    from:@"dominic@bombaxtic.com"
                                 headers:[NSDictionary dictionaryWithObject:@"text/html"
                                                                     forKey:@"Content-Type"]];
    return self;
}

@end

Objective C 将UINavigationBar添加到UITableView

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
 
tableViewNavigationBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
 
UIImage *image = [UIImage imageNamed:@"synyx_150_no_os.png"];
imageView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(84.0, 1.0, image.size.width, image.size.height) ];
[imageView setImage:image];
 
[tableViewNavigationBar addSubview:imageView];
 
[super.tableView addSubview:tableViewNavigationBar];
}


//This is the way i implemented in a Tab Bar Window

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	
	//navigationBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
	
	UIImage *image = [UIImage imageNamed:@"cpSmallLogoB.png"];
	UIImageView *imageView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(84.0, 22.0, image.size.width, image.size.height) ];
	[imageView setImage:image];
	
	//[navigationBar addSubview:imageView];
	
	[super.navigationController.view addSubview:imageView];
}

Objective C elementi BASE:gestione eventi tra classi

/** per registrare un azione in base ad un evento:
*/
    // Erase the view when recieving a notification named "shake" from the NSNotificationCenter object
	// The "shake" nofification is posted by the PaintingWindow object when user shakes the device
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eraseView) name:@"shake" object:nil];

/** INVIO dell'evento
*/

	// User was shaking the device. Post a notification named "shake".
	[[NSNotificationCenter defaultCenter] postNotificationName:@"shake" object:self];

Objective C C” YAE ??匆è§'å>¾ç‰‡

void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight);
{
	float fw, fh;
	if (ovalWidth == 0 || ovalHeight == 0) {
		CGContextAddRect(context, rect);
		return;
	}
	CGContextSaveGState(context);
	CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect));
	CGContextScaleCTM (context, ovalWidth, ovalHeight);
	fw = CGRectGetWidth (rect) / ovalWidth;
	fh = CGRectGetHeight (rect) / ovalHeight;
	CGContextMoveToPoint(context, fw, fh/2);
	CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);
	CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1);
	CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1);
	CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1);
	CGContextClosePath(context);
	CGContextRestoreGState(context);
}

- (UIImage *)roundCornersOfImage:(UIImage *)source;
{
	int w = source.size.width;
	int h = source.size.height;
	
	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
	CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
	
	CGContextBeginPath(context);
	CGRect rect = CGRectMake(0, 0, w, h);
	addRoundedRectToPath(context, rect, 5, 5);
	CGContextClosePath(context);
	CGContextClip(context);
	
	CGContextDrawImage(context, CGRectMake(0, 0, w, h), source.CGImage);
	
	CGImageRef imageMasked = CGBitmapContextCreateImage(context);
	CGContextRelease(context);
	CGColorSpaceRelease(colorSpace);
	
	return [UIImage imageWithCGImage:imageMasked];    
}

Objective C 使UIView不可见

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[myImageView setAlpha:0];
[UIView commitAnimations];

Objective C 如何初始化保留的财产

// Give a retained property
@property (retain) UILabel label;


// I believe that the following initializations 
// are equivalent and correct.

/////////////
UILabel *tmpLabel = [[UILabel alloc] init];
self.label = tmpLabel;
[tmpLabel release];

/////////////
self.label = [[[UILabel alloc] init] autorelease];

/////////////
label = [[UILabel alloc] init];

Objective C 山smb

NSURL *url = [NSURL URLWithString:@"smb://vf3.hsr.ch/skripte"];
FSVolumeRefNum volumeRefNum;
FSMountServerVolumeSync((CFURLRef)url, 
							NULL, 
							NULL, 
							NULL,
						&volumeRefNum, 
							 0
							 );