Open from today until November 5, the deadline for submission of the application for participation in the contest reserved for WordPress plugin developers: Win a 16GB iPhone5 for first place.
wpXtreme is coming: the free plugin that will revolutionize the user experience of WordPress is ready, and with him the WPX Store, the app store that will allow any developer to publish and sell your own plugin through the WPX Developer Center .
At https://wpxtre.me is available a preview of the main features that users will enjoy.
Continued ...
PHP IDE dedicated to the development there are many, ranging from free to those in charge. For a long time I have used tools such as Eclipse or Aptana , coming to serve specialized editors for HTML / Javascript and - even - CSS. For a year now, however, I think I found definitivamento a complete environment that, at least in my case, it solves all my problems: PhpStorm .
Continued ...
Comment HTML is a practice during the early stages of Web development However, the commented code is visible in the page, even if it is ignored by the browser. Selecting "View Source" or "View Code" from our browser, we will always be able to see it.
Continued ...
As already seen in Very short snippet: PHP word cut is more pleasing to break a text to "words", as it avoids to cut a word. There is, however those who prefer to cut counting the characters, as it makes the "cuts" more homogeneous and similar to each other, despite the substantial risk of cutting a word, mozzandola the net!
Continued ...
CGRectMake() is a function (actually it is an inline # define) used a lot especially when you create graphical objects by code or user interface. o UIImageView . CGRectMake() restituisce una struct (struttura di tipo) CGRect : Its use is therefore often linked to initialize components 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; |
. Which, in their turn again, contain types CGFloat , namely types float . If we analyze the code of the CGRectMake () are:
1 2 3 4 5 6 7 8
| CG_INLINE CGRect CGRectMake (CGFloat x, CGFloat y, CGFloat width, CGFloat height) { CGRect rect; y; rect.origin.x = x; rect.origin.y = y; height; rect.size.width = width; rect.size.height = height; return rect; } |
It follows, therefore, that this part of the 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" forState: UIControlStateNormal]; gbutton ] ; [MainWindow addSubview: GButton]; |
It may 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" forState: UIControlStateNormal]; gbutton ] ; [MainWindow addSubview: GButton]; |
Just to speed things up a bit 'the execution of the code ... 
Continued ...
Xcode is a very good development environment, nice and full of details that make writing code efficient and pleasant. Among them is definitely the convenience of the auto-complete as you type, especially when writing applications for Apple iPhone, where the frameworks are many and remember syntax and nomenclature is by undertaking a few.
Continued ...
As mentioned in the iPhone FirstApp: guess the number - Part 1 we see how to make an application for the Apple iPhone without using Interface Builder! Indeed, we will eliminate physically the files created by the wizard Interface Builder of Xcode. At the end of this post, then, we will have an application identical in all respects, to that achieved in the first part, with the difference that we will achieve all our visual components, including the main Window, completely to code.
The application already made, if you just want to download it, it is available on my Google Code repository:
I would like to point out immediately as the ZIP of this example weighs less than the last time! 
We create the project
Let's start creating our project SecondApp (to distinguish it from FirstApp), although this time we will choose Window-based Application:

Now let's remove everything related to Interface Builder. : eliminatelo anche dal file system, quindi selezionate Also Move to Trash . Eliminate the file MainWindow.xib , located in your Resources : also delete it from the file system, then choose Also Move to Trash. nella casella Main nib file base name : Selected, then the file SecondoApp-info.plist and delete the reference to the MainWindow in the box Main TR base file name:

At this point we no longer have any Window, at least through Interface Builder. , e modifichiamo la funzione main() in questo modo: Then open the file main.m , located in Other Sources , and modify the function main() in this way:
1 2 3 4 5 6 7 8 9 10 11
| int argc, char * argv [ ] ) { int main (int argc, char * argv []) { pool = [ [ NSAutoreleasePool alloc ] init ] ; NSAutoreleasePool * pool = [[ NSAutoreleasePool alloc] init]; / / Having deleted the file. Xib we lost pointing / / The app delegate, then pass it to "hand" UIApplicationMain ( argc, argv, nil , @ "SecondAppAppDelegate" ) ; int retVal = UIApplicationMain (argc, argv, nil, @ "SecondAppAppDelegate"); ; [Pool release]; return retVal; } |
Let's open SecondAppAppDelegate.me create the main Window in code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| void ) applicationDidFinishLaunching : ( UIApplication * ) application { - (Void) applicationDidFinishLaunching: (UIApplication *) application {
/ / Get the size of the screen (320, 480) UIScreen mainScreen ] applicationFrame ] ; CGRect windowRect = [[UIScreen mainScreen] applicationFrame]; / / Create a window - as we have done bye bye to Interface Builder [ [ UIWindow alloc ] initWithFrame : windowRect ] ; UIWindow * mainWindow = [[UIWindow alloc] initWithFrame: windowRect]; / / Set the background of the Window to yellow, to differentiate / / From the previous application FirstApp [ UIColor yellowColor ] ] ; [MainWindow setBackgroundColor: [UIColor Yellow Color]];
mainWindow ] ; [Self SetWindow: mainWindow]; ; [Window makeKeyAndVisible];
; [MainWindow release]; } |
You can already test the application, if you get a yellow window you did everything right!
, necessario solo se si usa Interface Builder. In the file SecondAppAppDelegate.h we can eliminate IBOutlet , only needed if you use Interface Builder. We also add here that our global variables, in the last time, we had entered into the controller. Then modify the file SecondAppAppDelegate.h :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # Import <UIKit/UIKit.h> NSObject <UIApplicationDelegate> { @ Interface SecondAppAppDelegate: NSObject {<UIApplicationDelegate> UIWindow * window; UITextField * number; UIButton * button; int numeroACaso; } nonatomic, retain ) UIWindow * window; @ Property (nonatomic, retain) UIWindow * window; void ) controllaNumero; - (Void) getNumber; @ End |
, in quanto non stiamo usando Interface Builder. Also in this case we have prepared the method definition controllaNumero , as last time, but we have eliminated the indication IBAction , since we are not using Interface Builder.
We build the interface code
It 'time to create code using all the components of our interface. ed inseriamo il seguente codice: Let's go back to the file SecondAppAppDelegate.m , posizioniamoci before the [mainWindow release] and insert the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| / / Create the title bar [ [ UINavigationBar alloc ] initWithFrame : CGRectMake ( 0.0 , 0.0 , 320.0 , 44.0 ) ] ; UINavigationBar * myNavigationBar = [[UINavigationBar alloc] initWithFrame: CGRectMake (0.0, 0.0, 320.0, 44.0)]; myNavigationBar.barStyle = UIBarStyleDefault; [ [ UINavigationItem alloc ] initWithTitle : @ "Indovina un numero" ] ; UINavigationItem navigationItem * = [[UINavigationItem alloc] initWithTitle: @ "Guess a number"]; navigationItem animated : NO ] ; [MyNavigationBar pushNavigationItem: navigationItem animated: NO]; myNavigationBar ] ; [Window addSubview: myNavigationBar];
/ / Create the label [ [ UILabel alloc ] initWithFrame : CGRectMake ( 10 , 50 , 300 , 80 ) ] ; UILabel * myLabel = [[UILabel alloc] initWithFrame: CGRectMake (10, 50, 300, 80)]; UIColor clearColor ] ; myLabel.backgroundColor = [UIColor clearColor]; ; myLabel.numberOfLines = 2; "iPhone ha pensato un numero da 1 a 10, prova ad indovinarlo?" ; myLabel.text = @ "iPhone has seen a number from 1 to 10, try to guess?" myLabel ] ; [Window addSubview: myLabel];
/ / Create text input UITextField alloc ] initWithFrame : CGRectMake ( 10 , 120 , 300 , 30 ) ] ; number = [[UITextField alloc] initWithFrame: CGRectMake (10, 120, 300, 30)]; numero.borderStyle = UITextBorderStyleRoundedRect; numero.textAlignment = UITextAlignmentCenter; numero.keyboardType = UIKeyboardTypeNumberPad; "Inserisci il numero" ; numero.placeholder = @ "Enter the number"; numero ] ; [Window addSubview: number];
/ / Create the button UIButton buttonWithType : UIButtonTypeRoundedRect ] ; button = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 10 , 180 , 300 , 30 ) ; bottone.frame = CGRectMake (10, 180, 300, 30); @ "Premi qui" forState : UIControlStateNormal ] ; [Button setTitle: @ "Click here" forState: UIControlStateNormal]; self action : @selector ( controllaNumero ) forControlEvents : UIControlEventTouchUpInside ] ; [AddTarget button: self action: @ selector (getNumber) forControlEvents: UIControlEventTouchUpInside]; bottone ] ; [Window addSubview: button];
; [MyLabel release]; ; [NavigationItem release]; ; [MyNavigationBar release]; |
della scorsa volta, subito dopo il [mainWindow release]; inseriamo: Since l ' applicationDidFinishLaunching corresponds to viewDidLoad of last time, immediately after the [mainWindow release]; insert:
1
| + arc4random ( ) % 10 ; numeroACaso arc4random = 1 + () 10%; |
Now we just have to implement the method controllaNumero , which will be identical (apart from the prototype) to the one used last time:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| void ) controllaNumero { - (Void) {getNumber "Premuto bottone di controlla numero" ) ; NSLog (@ "pressed button control number"); [ numero.text integerValue ] ; numeroInserito int = [numero.text integerValue]; message; NSString * message; "Il numero inserito è %d" , numeroInserito ) ; NSLog (@ "The number entered is% d", numeroInserito); numeroInserito <numeroACaso ) { if (numeroInserito <numeroACaso) { "Troppo basso..." ; message = @ "Too low ..."; ( numeroInserito> numeroACaso ) { } Else if (numeroInserito> numeroACaso) { "Troppo alto..." ; message = @ "Too high ..."; ( numeroInserito == numeroACaso ) { } Else if (numeroInserito numeroACaso ==) { "Bravo hai indovinato" ; message = @ "Bravo you guessed"; + arc4random ( ) % 10 ; numeroACaso arc4random = 1 + () 10%; "Numero pensato %d" , numeroACaso ) ; NSLog (@ "% d Number thought," numeroACaso); } [ [ UIAlertView alloc ] UIAlertView * alertMessaggio = [[UIAlertView alloc] "Responso" initWithTitle: @ "Response" message: message delegate: nil "OK" cancelButtonTitle: @ "OK" ] ; otherButtonTitles: nil]; ; [AlertMessaggio show]; ; [AlertMessaggio release]; "" ; numero.text = @ ""; } |
We are done!
Conclusions and considerations
, proprio perchè volevo lasciarlo il più semplice e snello possibile e, anche, per dimostrare che non sono elementi sempre necessari. This example does not make direct use of a UIView or a UIViewController , because I wanted to leave it as simple and streamlined as possible and, also, to show that items are not always necessary. However insert objects directly into the window can have some sense in this example and in other contexts sporadic. portano comunque benefici in tantissimi altri casi, ein alcuni sono praticamente indispensabili; come avremo modo di vedere in futuro. The use of UIView and UIViewController still bring benefits in many other cases, andin some are practically indispensable, as we will see in the future.
Continued ...
The Apple iPhone provides a limited number of fonts to developers. The list of available fonts is easily achieved by code, as we shall see. If you want to use your own fonts, such as including it in the resources, it is a bit more complex and conivolge also the issue of licenses (fees) on the font "embeddati" ... we'll talk later. Going back to the fonts present in Apple iPhone these are official (click image to zoom):
The Apple iPhone SDK gives you access to the special system fonts. These are identified by special constants and are:
1 2 3
| [ UIFont boldSystemFontOfSize : 12.0 ] ; UIFont myBoldFont * = [UIFont boldSystemFontOfSize: 12.0]; [ UIFont SystemFontOfSize : 12.0 ] ; UIFont mySystemFont * = [UIFont SystemFontOfSize: 12.0]; [ UIFont italicSystemFontOfSize : 12.0 ] ; UIFont myItalicFont * = [UIFont italicSystemFontOfSize: 12.0]; |
If instead you want to get a pointer to a font odei shown in the image above just use:
1
| [ UIFont fontWithName : @ "Helvetica-Bold" size : 22.0 ] ; UIFont myCustomFont * = [UIFont fontWithName: @ "Helvetica-Bold" size: 22.0]; |
As you may have noticed the management of the font is quite unusual addition to the family (Helvetica, Courier, etc ...) you have to specify the type (bold, italic, etc ...). In practice, therefore, a font should be provided with these characteristics. The Helvetica, for example, is present with:
1 2 3 4
| Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique |
If you want to view your font directly on your iPhone, here are a few lines of useful code:
1 2 3 4 5 6 7 8 9 10 11 12
| listOfFonts = [ [ NSArray alloc ] initWithArray : [ UIFont familyNames ] ] ; NSArray * listOfFonts = [[ NSArray alloc] initWithArray: [UIFont familynames]]; subFontTypes; NSArray * subFontTypes; int i = 0 ; i< [ listOfFonts count ] ; i ++ ) { for (int i = 0; i <[listOfFonts count]; i + +) { "Font Family: %@" , [ listOfFonts objectAtIndex : i ] ) ; NSLog (@ "Font Family:% @", [listOfFonts objectAtIndex: i]); NSArray alloc ] initWithArray : [ UIFont fontNamesForFamilyName : [ listOfFonts objectAtIndex : i ] ] ] ; subFontTypes = [[ NSArray alloc] initWithArray: [UIFont fontNamesForFamilyName: [listOfFonts objectAtIndex: i]]]; int j = 0 ; j< [ subFontTypes count ] ; j ++ ) { for (int j = 0; j <[subFontTypes count]; j + +) { "+----->Type: %@" , [ subFontTypes objectAtIndex : j ] ) ; NSLog (@ "+ -----> Type:% @", [subFontTypes objectAtIndex: j]); } ; [SubFontTypes release]; } ; [ListOfFonts release]; |
With the SDK 2.2.1, on my simulator, I got:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| Font Family: Courier + -----> Type: Courier + -----> Type: Courier-BoldOblique + -----> Type: Courier-Oblique + -----> Type: Courier-Bold Font Family: AppleGothic + -----> Type: AppleGothic Font Family: Arial + -----> Type: ArialMT + -----> Type: Arial-BoldMT + -----> Type: Arial-BoldItalicMT + -----> Type: Arial-ItalicMT Font Family: STHeiti TC + -----> Type: STHeitiTC-Light + -----> Type: Medium-STHeitiTC Font Family: Hiragino Kaku Gothic Pron + -----> Type: HiraKakuProN-W6 + -----> Type: HiraKakuProN-W3 Font Family: Courier New + -----> Type: CourierNewPS-BoldMT + -----> Type: CourierNewPS-ItalicMT + -----> Type: CourierNewPS-BoldItalicMT + -----> Type: CourierNewPSMT Font Family: Zapfino + -----> Type: Zapfino Font Family: Arial Unicode MS + -----> Type: ArialUnicodeMS Font Family: STHeiti SC + -----> Type: Medium-STHeitiSC + -----> Type: STHeitiSC-Light Font Family: American Typewriter + -----> Type: AmericanTypewriter + -----> Type: AmericanTypewriter-Bold Font Family: Helvetica + -----> Type: Helvetica-Oblique + -----> Type: Helvetica-BoldOblique + -----> Type: Helvetica + -----> Type: Helvetica-Bold Font Family: Marker Felt + -----> Type: Thin-MarkerFelt Font Family: Helvetica Neue + -----> Type: HelveticaNeue + -----> Type: HelveticaNeue-Bold Font Family: DB LCD Temp + -----> Type: DBLCDTempBlack Font family: Verdana + -----> Type: Verdana Bold- + -----> Type: Verdana-BoldItalic + -----> Type: Verdana + -----> Type: Verdana-Italic Font Family: Times New Roman + -----> Type: TimesNewRomanPSMT + -----> Type: TimesNewRomanPS-BoldMT + -----> Type: TimesNewRomanPS-BoldItalicMT + -----> Type: TimesNewRomanPS-ItalicMT Font Family: Georgia + -----> Type: Georgia-Bold + -----> Type: Georgia + -----> Type: Georgia-BoldItalic + -----> Type: Georgia-Italic Font Family: STHeiti J + -----> Type: Medium-STHeitiJ + -----> Type: STHeitiJ-Light Font Family: Arial Rounded MT Bold + -----> Type: ArialRoundedMTBold Font family: Trebuchet MS + -----> Type: TrebuchetMS-Italic + -----> Type: TrebuchetMS + -----> Type: Trebuchet-BoldItalic + -----> Type: TrebuchetMS-Bold Font Family: STHeiti K + -----> Type: Medium-STHeitiK + -----> Type: STHeitiK-Light |
Continued ...
The first source that I spent in my hands was written in Basic and consisted of a few lines of code, for enlightening me. It was a simple game that generated a random number from 1 to 10 and, through keyboard input, checked that the number entered was Maggione, less than or equal to the random number. Despite its rough simplicity remains, for me, one of the best examples - simple, fun and practical - to explain to those who do not know anything about programming actually what is meant by "computer program". So I thought to propose it for Apple iPhone, maybe someone will help ...
Continued ...
Latest Comments
Giovambattista Fazioli : @ ale: As shown @ Kevin see on GitHub repo: https://github.com/gfazioli/Ch roma-Key
Giovambattista Fazioli : @ Kevin: See https://github.com/gfazioli/Ch roma-Key
Kevin : Very nice example - would like to see the. fla too!
Ludovica : Hello! I'll explain my doubt. When I write a post not add pictures in the article (if so ...
Marco : hello @ Giovan Battista Fazioli, thanks for all the explanations of this excellent guide. I have a question to ...