I have bought some templates from App Design Vault and they are in XCode/Objective C. I would like to use them in Xamarin Studio/MonoTouch projects, how do I convert them so that they can be used similar to how some themes has been converted in Xamarin's Components Store?
Example of how the App Design Vault template is structured/layout can be downloaded from their website, they have a free template called Ocean: http://emitymeapps.us1.list-manage.com/subscribe/post?u=088ecce4e59f7a30e9aa859af&id=e59abf1e54
Thanks.
Ok, if you look in the AppDelegate.m file of their sample project, there are functions like this:
-(void)customizeiPhoneTheme
{
[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];
UIImage *navBarImage = [[UIImage tallImageNamed:#"menubar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 15, 5, 15)];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
UIImage *barButton = [[UIImage tallImageNamed:#"menubar-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
[[UIBarButtonItem appearance] setBackgroundImage:barButton forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
UIImage *backButton = [[UIImage tallImageNamed:#"back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 14, 0, 4)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
UIImage *minImage = [UIImage tallImageNamed:#"ipad-slider-fill"];
UIImage *maxImage = [UIImage tallImageNamed:#"ipad-slider-track.png"];
UIImage *thumbImage = [UIImage tallImageNamed:#"ipad-slider-handle.png"];
[[UISlider appearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal];
[[UISlider appearance] setMinimumTrackImage:minImage forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateHighlighted];
UIImage* tabBarBackground = [UIImage tallImageNamed:#"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage tallImageNamed:#"tabbar-active.png"]];
}
You are basically going to have to port this code to MonoTouch and add their images to your project. But it should be pretty easy, here is a couple lines of code translated to C#:
UIImage navBarImage = UIImage.FromFile("menubar.png").CreateResiableImage(new UIEdgeInsets(5, 15, 5, 15));
UINavigationBar.Appearance.SetBackgroundImage(navBarImage, UIBarMetrics.Default);
Check for mistakes, I did that off the top of my head. I'm also not sure what [UIImage tallImageNamed] is, it must be their own extension. I think you should just use UIImage.FromFile.
Related
I'm not sure if this is changeable, but I'm noticing a slight shadow on the title of my custom navigation controller.
Picture: http://imgur.com/60XjLWE
It's making the text look blurry, which is kind of annoying.
This is the code I'm using: [[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:52.0/255.0 green:54.0/255.0 blue:61.0/255.0 alpha:1.0],UITextAttributeTextColor,
[UIFont fontWithName:#"Helvetica Neue-Bold" size:0.0],UITextAttributeFont,
nil]];
Any idea how to remove the shadow on the title?
You can make it transparent:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:52.0/255.0 green:54.0/255.0 blue:61.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[UIFont fontWithName:#"Helvetica Neue-Bold" size:0.0], UITextAttributeFont, nil]];
Place this in your AppDelegate
[[UINavigationBar appearance]setShadowImage:[[UIImage alloc] init]];
This line of code has no effect. It does not change orientation of the image. What am I doing wrong?
// image is of type UIImage
UIImage * newImage = [UIImage imageWithCGImage:[image CGImage] scale:image.scale orientation:UIImageOrientationLeft];
Refer to the definition of this method below, make sure your CGImage is of a CGImageRef class.
imageWithCGImage:[image CGImage]
+(UIImage *)imageWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation
Following three lines are some initializations before you call the method.
CIContext * context = [CIContext contextWithOptions:nil]; //your choice
CIImage * OriginalImage = [CIImage imageWithContentsOfURL:fileNameAndPath]; //your own choice of source image file.
CGImageRef CGImage = [context createCGImage:OriginalImage fromRect:(CGRect)];
UIImage *newImage = [UIImage imageWithCGImage:CGImage scale:1.0 orientation:UIImageOrientationLeft]
Hope this helps.
In the drawrect function of a UIView I use CGContext to draw some shapes. This Works fine, I can see my shapes.
Now I'm trying to save what has been drawn on the view as a png on disk. I've read various docs / articles but nothing gets saved. Im testing on the simulator for ios 4.3.
Edit 1
I changed my code and uncommented the context part. I can save the png but it is blank.
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx= UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(ctx, 0, 0, 0, .5);
CGContextBeginPath(ctx);
CGContextAddPath(ctx, mutatablepath);
//CGContextStrokePath(ctx);
CGContextFillPath(ctx);
CFRelease(mutatablepath);
NSString *path0;
NSArray *paths0=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path0=[[paths0 objectAtIndex:0]stringByAppendingPathComponent:#"images"];
NSError *error;
if (![[NSFileManager defaultManager]fileExistsAtPath:path0]) {
if(![[NSFileManager defaultManager]createDirectoryAtPath:path0 withIntermediateDirectories:NO attributes:nil error:&error])
{
NSLog(#"Create directory error %#",error);
}
}
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imagedata=UIImagePNGRepresentation(image);
NSString *namepath=[NSString stringWithFormat:#"%#.png",#"test"];
NSString *path;
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path=[[paths objectAtIndex:0]stringByAppendingPathComponent:#"images"];
NSString *savepath=[NSString stringWithFormat:#"%#/%#",path,namepath ];
// NSError
NSLog(#"%#",savepath);
[imagedata writeToFile:savepath atomically:YES];
}
You can do so by taking the image saving code out of your drawRect method, since the renderInContext method implicitly calls drawRect as necessary:
UIView *myView = [[MyViewClass alloc] initWithFrame:CGRectMake(/*...*/)];
UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Source: http://pastie.org/244916
Using the below code I am implementing my own Navigation Bar. For some reason when I run my app nothing is showing up for a back (left-arrow) button on the navigation bar. However if I change the code to leftBarButtonItem, the button does appear.
// Draw Navigation Bar
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navigationBar setDelegate:self];
UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
navigationItem.backBarButtonItem = backButton;
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];
[navigationBar release];
[backButton release];
The backBarButtonItem is set by the parent ViewController.
In other words, it's not set by the ViewController on which you see it but by the ViewController to which it points. So if your ViewController is the first in line, it just won't have a back button.
Also, you are creating a NavigtionBar by yourself. This is usually not the way to go, a UINavigationBar isn't a UI-Element like a Button or a Label. You should rather use a UINavigationController to handle all the pushing and popping of your ViewControllers.
Figured it out:
// Draw Navigation Bar
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navigationBar setDelegate:self];
UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
UIButton *button = [UIButton buttonWithType:101];
// add selector
[button setTitle:#"Back" forState:UIControlStateNormal];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
navigationItem.leftBarButtonItem = backButton;
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];
[navigationBar release];
[backButton release];
Hi!I have used UIBarButton Image but i have got such kind of issue.i mean Image+button on backside.for that i have written code below.
UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"mapbutton.png"] style:UIBarButtonItemStylePlain target:self action:#selector(btnMapClicked:)];
self.navigationItem.rightBarButtonItem = btnMap;
[btnMap release];
Use initWithCustomView and set a UIButton as the customView instead:
UIButton *subBtn = [UIButton buttonWithType:UIButtonTypeCustom];
subBtn.frame = CGRectMake(0, 0, 50, 40); //adjust as needed
[subBtn setImage:[UIImage imageNamed:#"mapbutton.png"] forState:UIControlStateNormal];
[subBtn addTarget:self action:#selector(btnMapClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithCustomView:subBtn];
self.navigationItem.rightBarButtonItem = btnMap;
[btnMap release];
Note that the sender in btnMapClicked: will now be a UIButton instead of a UIBarButtonItem.