http://chris-software.com/index.php/2009/05/08/creating-programmatically-a-label-uilabel/
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];
myLabel.text = @"Lorem...";
self.view addSubview:myLabel];
myLabel.backgroundColor = [UIColor clearColor]; // [UIColor brownColor]
myLabel.font = [UIFont fontWithName:@"Zapfino" size: 14.0];
Setting the font:
myLabel.shadowColor = [UIColor grayColor];
myLabel.shadowOffset = CGSizeMake(1,1);
myLabel.textColor = [UIColor blueColor];
myLabel.textAlignment = UITextAlignmentRight;
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 2; // 2 lines ; 0 - dynamical number of lines
myLabel.text = @"Lorem ipsum dolor sit\namet...";
Friday, May 21, 2010
Thursday, May 20, 2010
How to check if a file exists in Documents folder?
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"dirname/file.name"];
//check if file exists
NSFileManager *fm = [NSFileManager defaultManager];
BOOL success = [fm fileExistsAtPath:filePath];
Another Way
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* foofile = [documentsPath stringByAppendingPathComponent:@"foo.html"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
//check if file exists
NSFileManager *fm = [NSFileManager defaultManager];
BOOL success = [fm fileExistsAtPath:filePath];
Another Way
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* foofile = [documentsPath stringByAppendingPathComponent:@"foo.html"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
Save File in app Folder
http://www.iphonedevsdk.com/forum/iphone-sdk-development/47813-save-image-app-folder.html
- (void)saveImage:(UIImage *)image withName:(NSString *)name {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];
if(![fileManager createFileAtPath:fullPath contents:data attributes:nil])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved Failed." message:@"Saved Failed." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved." message:@"Saved." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
}
- (void)saveImage:(UIImage *)image withName:(NSString *)name {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];
if(![fileManager createFileAtPath:fullPath contents:data attributes:nil])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved Failed." message:@"Saved Failed." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved." message:@"Saved." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
}
Monday, May 17, 2010
String Operations in objective c
http://www.techotopia.com/index.php/Working_with_String_Objects_in_Objective-C
Friday, May 14, 2010
f you want to read the file into a string, which you can then display in a UITextView, for example, then do this
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"important" ofType:@"txt"];
if (filePath) {
NSString *myText = [NSString stringWithContentsOfFile:filePath];
if (myText) {
textView.text= myText;
}
}
if (filePath) {
NSString *myText = [NSString stringWithContentsOfFile:filePath];
if (myText) {
textView.text= myText;
}
}
Here’s a complete example reading a help text file into a UIWebView
.
view plaincopy to clipboardprint?
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"HelpDoc" ofType:@"htm"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
if (htmlData) {
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://iphoneincubator.com"]];
}
view plaincopy to clipboardprint?
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"HelpDoc" ofType:@"htm"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
if (htmlData) {
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://iphoneincubator.com"]];
}
How To Read a File From Your Application Bundle
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"txt"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
if (myData) {
// do something useful
}
NSData *myData = [NSData dataWithContentsOfFile:filePath];
if (myData) {
// do something useful
}
Subscribe to:
Posts (Atom)