How to make iPhone app smaller on iPad? - objective-c

I have converted ILColorPicker to work on XCode4 and Storyboard. My problem is that it fills the entire UIView on the iPad... where do I start looking for a way to make it smaller?
I was thinking of using a subview, but not sure how to "wire" it into the subview. Any other ideas?
UPDATE: here is the code where I believe I can modify the frame, except I don't know how...
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}

Adjusting the frame size is programmed with CGRectMake like this:
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:CGRectMake(x, y, width, height)])) {
// Initialization code
}
return self;
}
In the above the variable x and y corrispond to the top-left corner. And width and height are the width and height of the frame.

Related

How to customise scene size in SpriteKite using initWithSize

I need to lay a new scene on top of the old one, so that an upper band of the old one remains visible at the top. How should I modify initWithSize below?
- (id)initWithSize:(CGSize)size
{
self = [super initWithSize:size];
if (self)
{
//code
}
}
I tried using:
self = [super initWithSize:CGSizeMake(size.width, size.height +30)];
instead of
self = [super initWithSize:size];
but it doesn't work. It simply compresses vertically the scene a bit, but I still cannot see the underlying old scene. Cheers.

View bounds and coordinates in Cocoa Mac OS X

I have a simple custom view in my Mac OS X application that is essentially empty. Here is the code:
#implementation MyDrawingView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
NSLog(#"bounds:x:%f y:%f w:%f h:%f", self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.bounds.size.height);
}
#end
Here is the output of NSLog:
bounds:x:0.000000 y:0.000000 w:713.000000 h:509.000000
I read about user space here: Coordinate Systems and Transforms
Does this mean that my view is going to show 713/72 inches wide on screen? It doesn't show up that wide in reality. I have a background color set on my view so I can see it just as wide as it really is.
the view is 713 points wide. 713*screenscale = pixel size which you can then use with dpi to get the inches shown ;)

drawRect in UIView subclass doesn't update image

I have a UIView subclass that I would like to use to draw images with different blend modes.
code:
#implementation CompositeImageView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)setBlendMode:(CGBlendMode) composite
{
blender = composite;
}
-(void)setImage:(UIImage*) img
{
image = img;
}
- (void)drawRect:(CGRect)rect
{
NSLog(#"it draws");
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(c, blender);
CGContextDrawImage(c, rect, image.CGImage);
}
#end
the code that I use to set it up it is:
[testImage setImage:[UIImage imageNamed:#"Prayer_Background_Paid"]];
[testImage setBlendMode:kCGBlendModeColor];
[testImage setNeedsDisplay];
I am using the interface builder to place a large rectangular UIView, and then set its class to CompositeImageView. However, it still draws as a large white square. Even if I comment out everything inside drawRect, it still draws the white square. However, it IS calling drawRect, because "it draws" is being logged.
Are you sure kCGBlendModeColor is what you want? From the Apple doc:
Uses the luminance values of the background with the hue and
saturation values of the source image.
It seems that if it was a white background, the blended image would also appear white.

How to stop UIScrollView when leave touch

I made UIScrollView with some UIButton inside. The problem is that when I scroll down at the end of view, it return on start. What can i do? I use this in viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad]; // step 3
scroll.scrollEnabled=YES;
scroll.contentSize = [self.view sizeThatFits:CGSizeZero];
}
According to Apple Documentation: sizeThatFits returns the size portion of the view’s bounds rectangle.
So your scroll view content size is of the same size of the UIView, thats why the scroll view returns to its original position. You need to set the height of the content size to the total height of your entire content in the scroll view. Normally this is bigger, because otherwise it won't make sense to use a UIViewController.
So, use something like this and it should work:
- (void)viewDidLoad
{
[super viewDidLoad]; // step 3
scroll.scrollEnabled=YES;
CGSize scrollViewSize = [self.view sizeThatFits:CGSizeZero];
scrollViewSize.height = 800.0; // Set here the height of the total area of your ScrollView. Should be bigger than the visible area.
scroll.contentSize = scrollViewSize;
}

Adding Padding To The 'left' of a Text Field

I have a text field with a background but to make it look right the text field needs to have some padding on the left side of it a bit like the NSSearchField does. How would I give the text field some padding on the left?
smorgan's answer points us in the right direction, but it took me quite a while to figure out how to restore the customized textfield's ability to display a background color -- you must call setBorder:YES on the custom cell.
This is too late to help Joshua, but here's the how you implement the customized cell:
#import <Foundation/Foundation.h>
// subclass NSTextFieldCell
#interface InstructionsTextFieldCell : NSTextFieldCell {
}
#end
#import "InstructionsTextFieldCell.h"
#implementation InstructionsTextFieldCell
- (id)init
{
self = [super init];
if (self) {
// Initialization code here. (None needed.)
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (NSRect)drawingRectForBounds:(NSRect)rect {
// This gives pretty generous margins, suitable for a large font size.
// If you're using the default font size, it would probably be better to cut the inset values in half.
// You could also propertize a CGFloat from which to derive the inset values, and set it per the font size used at any given time.
NSRect rectInset = NSMakeRect(rect.origin.x + 10.0f, rect.origin.y + 10.0f, rect.size.width - 20.0f, rect.size.height - 20.0f);
return [super drawingRectForBounds:rectInset];
}
// Required methods
- (id)initWithCoder:(NSCoder *)decoder {
return [super initWithCoder:decoder];
}
- (id)initImageCell:(NSImage *)image {
return [super initImageCell:image];
}
- (id)initTextCell:(NSString *)string {
return [super initTextCell:string];
}
#end
(If, like Joshua, you only want an inset at the left, leave the origin.y and height as is, and add the same amount to the width -- not double -- as you do to the origin.x.)
Assign the customized cell like this, in the awakeFromNib method of the window/view controller that owns the textfield:
// Assign the textfield a customized cell, inset so that text doesn't run all the way to the edge.
InstructionsTextFieldCell *newCell = [[InstructionsTextFieldCell alloc] init];
[newCell setBordered:YES]; // so background color shows up
[newCell setBezeled:YES];
[self.tfSyncInstructions setCell:newCell];
[newCell release];
Use a custom NSTextFieldCell that overrides drawingRectForBounds:. Have it inset the rectangle by however much you want, then pass than new rectangle to [super drawingRectForBounds:] to get the normal padding, and return the result of that call.