Answer to the question of ILeW with an article about what the real, attaching such as notifications and delegates work. Using a pattern we see first how the delegate pattern:

An object in search of a delegate
Answer to the question of ILeW with an article about what the real, attaching such as notifications and delegates work. Using a pattern we see first how the delegate pattern:

An object in search of a delegate
The simulator iPhones / iPad Xcode allows you to simulate the double tap the Alt key is pressed. This is useful to simulate the function of Pinch, that used to enlarge or scroll Keep away content in the view with objects or UIWebView . Well, some of you have noticed that the simulation of the "two fingers" proceeds in a symmetrical manner always starting from the center of the screen. To move this "center" is also just hold down the SHIFT key.
potremmo aver necessità di personalizzare la grafica dei titoli delle sezioni, come California o New York dell'esempio qui sotto. When we use a UITableView style Grouped we may need to customize the layout of section titles, such as California or New York the example below.

To do so, please use the following code, placing it in the delegate, ie in the class that responds to the protocol UITableViewDelegate :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | / / Returns View my custom, in this case an object / / Type UILabel UIView * ) tableView : ( UITableView * ) tableView - (UIView *) tableView: (UITableView *) tableView NSInteger ) section { viewForHeaderInSection: (NSInteger) section { [ [ [ UILabel alloc ] initWithFrame : CGRectZero ] autorelease ] ; UILabel * label = [[[UILabel alloc] initWithFrame: CGRectZero] autorelease]; UIFont boldSystemFontOfSize : 20 ] ; label.font = [UIFont boldSystemFontOfSize: 20]; label.textAlignment = UITextAlignmentCenter; UIColor blackColor ] ; label.shadowColor = [UIColor blackColor]; 1 , 1 ) ; label.shadowOffset CGSizeMake = (1, 1); "Sezione" ; // Sostituire con un array come al solito Label.Text @ = "Section", / / Replace with an array as usual UIColor whiteColor ] ; label.textColor = [UIColor whiteColor]; UIColor clearColor ] ; label.backgroundColor = [UIColor clearColor]; ; label.opaque = NO; return label; } / / We must also support this message does not work otherwise CGFloat ) tableView : ( UITableView * ) tableView - (CGFloat) tableView: (UITableView *) tableView NSInteger ) section { heightForHeaderInSection: (NSInteger) section { ; return 44; } |
It is also important to include heightForHeaderInSection , will not work.
o UIImageView , ho utilizzato per inizializzare il frame CGRectZero che corrisponde a CGRectMake(0,0,0,0) . In the creation of our UILabel , which might also be wanting a more complex object like a UIView or UIImageView , I used to initialize the frame CGRectZero corresponding to CGRectMake(0,0,0,0) .
non funzionano quando un UIButton è impostato in modalità UIButtonTypeCustom ! The states UIControlStateSelected or UIControlStateHighlighted not work when a UIButton mode is set UIButtonTypeCustom ! Or rather, do not work (because reserved for other types of button), for example to create a two-state button: toggle note. If we have created two images (and stato1.png stato2.png) for our button, we can proceed as follows:
1 2 3 | / / The header files that we create a global variable for usaremo / / Check the toggle were ToggleFlag BOOL; |
Now we create our button:
1 2 3 4 5 6 7 8 9 | / / We create a button and we place it initially in the state "stato1.png" / / Edit initWithFrame: (CGRect) {100,100,50,50} with the location and / / Size of your image has ; toggleFlag = YES; [ [ UIButton buttonWithType : UIButtonTypeCustom ] initWithFrame : ( CGRect ) { 100 , 100 , 50 , 50 } ] ; UIButton ToggleButton * = [[UIButton buttonWithType: UIButtonTypeCustom] initWithFrame: (CGRect) {100, 100, 50, 50}]; @ "" forState : UIControlStateNormal ] ; [ToggleButton setTitle: @ "" Forst: UIControlStateNormal]; [ UIImage imageNamed : @ "stato1.png" ] forState : UIControlStateNormal ] ; [ToggleButton setBackgroundImage: [UIImage imageNamed: @ "stato1.png"] Forst: UIControlStateNormal]; self action : @selector ( onToggle : ) forControlEvents : UIControlEventTouchUpInside ] ; [ToggleButton addTarget: self action: @ selector (onToggle:) forControlEvents: UIControlEventTouchUpInside]; toggleButton ] ; [Self.view addSubview: ToggleButton]; |
When you click on the button will send a message to be managed onToggle :
1 2 3 4 5 6 7 | void ) onToggle : ( id ) sender { - (Void) onToggle: (id) sender { / / Retrieve pointer to UIButton ( UIButton * ) sender; UIButton ButtonClicked * = (UIButton *) sender; / / Execute Toogle toggleFlag =! toggleFlag; [ UIImage imageNamed : ( toggleFlag ) ? @ "stato1.png" : @ "stato2.png" ] forState : UIControlStateNormal ] ; [ButtonClicked setBackgroundImage: [UIImage imageNamed: (toggleFlag)? @ "Stato1.png" @ "stato2.png"] Forst: UIControlStateNormal]; } |
o CGPoint , ad esempio. The syntax NSLog(@"%@", ... ); works and is used to obtain information about objects, but does not work on C data types such as struct CGRect or CGPoint , for example. o NSStringFromCGPoint : To take advantage of NSLog(@"%@", ... ); even on C-style structs can rely on conversion functions like NSStringFromCGRect() or NSStringFromCGPoint :
1 2 3 4 5 | CGRect ) { 10 , 20 , 30 , 40 } ; CGRect mioRect = (CGRect) {10, 20, 30, 40}; CGPoint ) { 32 , 64 } ; CGPoint mioPoint = (CGPoint) {32, 64}; / / "Info rettangolo: %@" , NSStringFromCGRect ( mioRect ) ) ; NSLog (@ "Info rectangle:% @", NSStringFromCGRect (mioRect)); "Info point: %@" , NSStringFromCGPoint ( mioPoint ) ) ; NSLog (@ "Info point:% @", NSStringFromCGPoint (mioPoint)); |
Specifically, it is possible to improve this procedure writes of small useful macros like:
1 | # Define NSLogRect (rect) NSLog (@ "% s (% 0.0f,% 0.0f)% 0.0f% 0.0fx", # rect, rect.origin.x, rect.origin.y, rect.size.width , rect.size.height) |
Or:
1 2 3 4 | # Define NSLogCGPoint (point) NSLog (@ "% s (% 0.0f,% 0.0f)", # point.x point, Point.y) CGPoint ) { 32 , 64 } ; CGPoint mioPoint = (CGPoint) {32, 64}; ; NSLogCGPoint (mioPoint); |
That will give as output:
1 | 32 , 64 ) mioPoint: (32, 64) |
CGRectMake() is a function (actually an inline # define) used a lot especially when you create graphics objects from code or user interface. o UIImageView . CGRectMake() restituisce una struct (struttura di tipo) CGRect : Its use is therefore often associated initialization components of UIKit , but also to simple UIView or UIImageView . CGRectMake() returns a struct (structure type) CGRect :
1 2 3 4 5 | struct {CGRect CGPoint origin; CGSize size; }; typedef struct CGRect CGRect; |
: Which in turn is composed of two different struct CGPoint and CGSize :
1 2 3 4 5 6 7 8 9 10 11 12 13 | struct {CGPoint CGFloat x; CGFloat y; }; typedef struct CGPoint CGPoint; / * Sizes. * / struct {CGSize CGFloat width; CGFloat height; }; typedef struct CGSize CGSize; |
. That, in turn, again, contain types CGFloat or type float . If we analyze the code of CGRectMake () are:
1 2 3 4 5 6 7 8 | CG_INLINE CGRect CGRectMake (CGFloat x, y CGFloat, CGFloat width, height CGFloat) { CGRect rect; y; rect.origin.x = x, y = rect.origin.y; height; rect.size.width = width, height = rect.size.height; return rect; } |
It follows, therefore, that this piece of code:
1 2 3 4 | [ UIButton buttonWithType : UIButtonTypeRoundedRect ] ; UIButton gbutton * = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 12 , 409 , 100 , 40 ) ; gbutton.frame = CGRectMake (12, 409, 100, 40); @ "Press" forState : UIControlStateNormal ] ; [Gbutton setTitle: @ "Press" Forst: UIControlStateNormal]; gbutton ] ; [MainWindow addSubview: gbutton]; |
It could rightly be written as:
1 2 3 4 | [ UIButton buttonWithType : UIButtonTypeRoundedRect ] ; UIButton gbutton * = [UIButton buttonWithType: UIButtonTypeRoundedRect]; CGRect ) { 12 , 409 , 100 , 40 } ; gbutton.frame = (CGRect) {12, 409, 100, 40}; @ "Press" forState : UIControlStateNormal ] ; [Gbutton setTitle: @ "Press" Forst: UIControlStateNormal]; gbutton ] ; [MainWindow addSubview: gbutton]; |
Just to speed things up 'the code is running ... ![]()
Latest Comments
Mark : @ Mark: Thanks for the answer. For example, if you have a code to save / use the folder ...
Mark : Thanks for the answer. For example, if you have a code to save / use the folder ...
Giovambattista Fazioli : @ Mark: in principle, absolutely, a lot depends on how and what to download. La. ..
Mark : Hello, good guide! I wanted to ask, you can use the same code to run a sql database? Instead of ...
Joseph : Hi I wanted to ask you how you can do in the post I uploaded a gallery of 50 images, for example, ...