[Android] 타이틀바 없애기

<application
        android:icon="@drawable/icon"
        android:label="@string/app_
name"
        android:theme="@android:style/Theme.NoTitleBar">


참고 : http://uknowapps.egloos.com/1515393

Posted by incree

2011/11/29 17:34 2011/11/29 17:34
,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/73

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

<activity android:name=".youractivity"
                  android:label="@string/app_
name"
                  android:configChanges="orientation|keyboardHidden">


참고 : http://www.androidpub.com/742429

Posted by incree

2011/11/29 17:33 2011/11/29 17:33
,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/72

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

nohup grep -RFl -e csex -e cname -e cssnum -e cbirthday -e bwreg -e bwcid * &

Posted by incree

2011/09/29 18:40 2011/09/29 18:40
,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/47

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

onpropertychange


Posted by incree

2011/09/28 23:34 2011/09/28 23:34
, , ,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/46

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

[iPhone]주어진 넓이 만큼 문자열 자르기

http://lambert.tistory.com/480
https://gist.github.com/906714


NSString-truncateToSize.h

//
// NSString-truncateToSize
// Fast Fonts
//
// Created by Stuart Shelton on 28/03/2010.
// Copyright 2010 Stuart Shelton.
//
// NSString truncate function for Objective C / iPhone SDK by
// Stuart Shelton is licensed under a Creative Commons Attribution 3.0
// Unported License (CC BY 3.0)
//
// http://creativecommons.org/licenses/by/3.0/
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NSString (truncateToSize)
- (NSString *)truncateToSize: (CGSize)size withFont: (UIFont *)font lineBreakMode: (UILineBreakMode)lineBreakMode;
- (NSString *)truncateToSize: (CGSize)size withFont: (UIFont *)font lineBreakMode: (UILineBreakMode)lineBreakMode withAnchor: (NSString *)anchor;
- (NSString *)truncateToSize: (CGSize)size withFont: (UIFont *)font lineBreakMode: (UILineBreakMode)lineBreakMode withStartingAnchor: (NSString *)startingAnchor withEndingAnchor: (NSString *)endingAnchor;
@end
NSString-truncateToSize.m
//
// NSString-truncateToSize
// Fast Fonts
//
// Created by Stuart Shelton on 28/03/2010.
// Copyright 2010 Stuart Shelton.
//
// NSString truncate function for Objective C / iPhone SDK by
// Stuart Shelton is licensed under a Creative Commons Attribution 3.0
// Unported License (CC BY 3.0)
//
// http://creativecommons.org/licenses/by/3.0/
//
#import "NSString-truncateToSize.h"
@implementation NSString (truncateToSize)
- (NSString *)truncateToSize: (CGSize)size withFont: (UIFont *)font lineBreakMode: (UILineBreakMode)lineBreakMode {
    return [self truncateToSize: size withFont: font lineBreakMode: lineBreakMode withStartingAnchor: nil withEndingAnchor: nil];
} /* (NSString *)truncateToSize: withFont: lineBreakMode: */
- (NSString *)truncateToSize: (CGSize)size withFont: (UIFont *)font lineBreakMode: (UILineBreakMode)lineBreakMode withAnchor: (NSString *)anchor {
    return [self truncateToSize: size withFont: font lineBreakMode: lineBreakMode withStartingAnchor: anchor withEndingAnchor: anchor];
} /* (NSString *)truncateToSize: withFont: lineBreakMode: withAnchor: */
- (NSString *)truncateToSize: (CGSize)size withFont: (UIFont *)font lineBreakMode: (UILineBreakMode)lineBreakMode withStartingAnchor: (NSString *)startingAnchor withEndingAnchor: (NSString *)endingAnchor {
    if( !( lineBreakMode & ( UILineBreakModeHeadTruncation | UILineBreakModeMiddleTruncation | UILineBreakModeTailTruncation ) ) )
        return self;
    if( [self sizeWithFont: font].width <= size.width )
        return self;
   
    NSString *ellipsis = @"…";
    // Note that this code will find the first occurrence of any given anchor,
    // so be careful when choosing anchor characters/strings...
    NSInteger start;
    if( startingAnchor ) {
        start = [self rangeOfString: startingAnchor options: NSLiteralSearch].location;
        if( NSNotFound == start ) {
            if( [startingAnchor isEqualToString: endingAnchor] )
                return [self truncateToSize: size withFont: font lineBreakMode: lineBreakMode];
            else
                return [self truncateToSize: size withFont: font lineBreakMode: lineBreakMode withAnchor: endingAnchor];
        }
    } else {
        start = 0;
    }
   
    NSUInteger end;
    if( endingAnchor ) {
        end = [self rangeOfString: endingAnchor options: NSLiteralSearch range: NSMakeRange( start + 1, [self length] - start - 1 )].location;
        if( NSNotFound == end ) {
            if( [startingAnchor isEqualToString: endingAnchor] )
                // Shouldn't ever occur, since filtered out in block above...
                return [self truncateToSize: size withFont: font lineBreakMode: lineBreakMode];
            else
                return [self truncateToSize: size withFont: font lineBreakMode: lineBreakMode withAnchor: startingAnchor];
        }
    } else {
        end = [self length];
    }
    NSUInteger targetLength = end - start;
    if( [[self substringWithRange: NSMakeRange( start, targetLength )] sizeWithFont: font].width < [ellipsis sizeWithFont: font].width )
        if( startingAnchor || endingAnchor )
            return [self truncateToSize: size withFont: font lineBreakMode: lineBreakMode];
        else
            return self;
   
    NSMutableString *truncatedString = [[NSMutableString alloc] initWithString: self];
   
    switch( lineBreakMode ) {
        case UILineBreakModeHeadTruncation:
            // Avoid anchor...
            if( startingAnchor )
                start++;
            while( targetLength > [ellipsis length] + 1 && [truncatedString sizeWithFont: font].width > size.width) {
                // Replace our ellipsis and one additional following character with our ellipsis
                NSRange range = NSMakeRange( start, [ellipsis length] + 1 );
                [truncatedString replaceCharactersInRange: range withString: ellipsis];
                targetLength--;
            }
            break;
           
        case UILineBreakModeMiddleTruncation:
        {
            NSUInteger leftEnd = start + ( targetLength / 2 );
            NSUInteger rightStart = leftEnd + 1;
            if( leftEnd + 1 <= rightStart - 1 )
                break;
           
            // leftPre and rightPost consist of any characters before and beyond
            // any specified anchor(s).
            // left and right are the two halves of the string to be truncated - although
            // the initial split is still performed based upon the length of the
            // (sub)string to be truncated, so we could still make a bad initial split given
            // a short string with predominantly narrow characters on one side and wide
            // characters on the other.
            NSString *leftPre = @"";
            if( startingAnchor )
                leftPre = [truncatedString substringWithRange: NSMakeRange( 0, start + 1 )];
            NSMutableString *left = [NSMutableString stringWithString: [truncatedString substringWithRange: NSMakeRange( ( startingAnchor ? start + 1 : start ), leftEnd - start )]];
            NSMutableString *right = [NSMutableString stringWithString: [truncatedString substringWithRange: NSMakeRange( rightStart, end - rightStart )]];
            NSString *rightPost = @"";
            if( endingAnchor )
                rightPost = [truncatedString substringWithRange: NSMakeRange( end, [truncatedString length] - end )];
           
            /* NSLog( @"pre '%@', left '%@', right '%@', post '%@'", leftPre, left, right, rightPost ); */
            // Reassemble substrings
            [truncatedString setString: [NSString stringWithFormat: @"%@%@%@%@%@", leftPre, left, ellipsis, right, rightPost]];
           
            while( leftEnd > start + 1 && rightStart < end + 1 && [truncatedString sizeWithFont: font].width > size.width) {
                CGFloat leftLength = [left sizeWithFont: font].width;
                CGFloat rightLength = [right sizeWithFont: font].width;
               
                // Shorten string of longest width
                if( leftLength > rightLength ) {
                    [left deleteCharactersInRange: NSMakeRange( [left length] - 1, 1 )];
                    leftEnd--;
                } else { /* ( leftLength <= rightLength ) */
                    [right deleteCharactersInRange: NSMakeRange( 0, 1 )];
                    rightStart++;
                }
               
                /* NSLog( @"pre '%@', left '%@', right'%@', post '%@'", leftPre, left, right, rightPost ); */
                [truncatedString setString: [NSString stringWithFormat: @"%@%@%@%@%@", leftPre, left, ellipsis, right, rightPost]];
            }
        }
            break;
           
        case UILineBreakModeTailTruncation:
            while( targetLength > [ellipsis length] + 1 && [truncatedString sizeWithFont: font].width > size.width) {
                // Remove last character
                NSRange range = NSMakeRange( --end, 1);
                [truncatedString deleteCharactersInRange: range];
                // Replace original last-but-one (now last) character with our ellipsis...
                range = NSMakeRange( end - [ellipsis length], [ellipsis length] );
                [truncatedString replaceCharactersInRange: range withString: ellipsis];
                targetLength--;
            }
            break;
    }
   
    NSString *result = [NSString stringWithString: truncatedString];
    [truncatedString release];
    return result;
} /* (NSString *)truncateToSize: withFont: lineBreakMode: withStartingAnchor: withEndingAnchor: */
@end

Posted by incree

2011/09/17 04:56 2011/09/17 04:56
,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/34

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

var cm:ContextMenu = new ContextMenu();
cm.hideBuiltInItems();
var cmi:ContextMenuItem = new ContextMenuItem("인크리");
cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuHandler);
cm.customItems.push(cmi);
this.contextMenu = cm;

function contextMenuHandler(event:ContextMenuEvent) {
    JavascriptUtil.openLink("http://www.incree.com", "_blank");
}

Posted by incree

2011/09/06 12:34 2011/09/06 12:34
,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/28

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

[iPhone]삭제시 흔들리는 아이콘

http://undefinedvalue.com/2010/02/05/iphone-sample-code-tiles

iPhone Sample Code: Tiles

As an exercise in using the Core Animation API, I've implemented a little iPhone app that reproduces the behavior of the iPhone home screen's icon reorganization interface. (You know, dragging the wiggly icons around.) You can download my sample code to see how it works. Some descriptions of the highlights follow below.

Screenshot

The source code and Xcode project can be downloaded here: Tiles-v1.0.zip.

Source is also available on GitHub. (If you're a Mercurial user, you may want to grab it from bitbucket.org.)

The primary classes to look at are TilesViewController and Tile. The view controller implements all of the "logic" of the application, while the Tile class has the animations.

An instance of Tile represents one of the icons, and is derived from CAGradientLayer. The gradient layer properties get set to provide a gloss effect for the tiles. Tile also provides a few animations, initiated by calling these methods:

  • appearDraggable: Changes the tile to be partially transparent, and makes it slightly bigger. This is invoked when the user touches a tile.
  • appearNormal: Reverses the effects of appearDraggable. This is invoked when the tile is released.
  • startWiggling: Starts a tile "wiggling", as in the iPhone home screen while in reorganization mode.
  • stopWiggling: Stops the wiggling effect

The TilesViewController class is pretty straightforward. When the user touches a the screen, the touchesBegan method determines which tile was touched, calls its appearDraggable method, and calls other tiles' startWiggling methods.

As the user drags the tile around the screen, the touchesMoved method moves the dragged tile, and moves the other tiles as needed to provide an open space for it. Core Animation takes care of all the zooming around of the icons.

When the user lets go of the tile, the touchesEnded method drops it in place and removes all the animations.

Things I learned from this project:

  • Turning on the masksToBounds property for layers slows things down quite noticeably.
  • When hit-testing layers, you have to use a layer's presentation layer, not a model layer itself.
  • CAGradientLayer is easy to use.

Here are some things I don't understand. (Maybe some smart person can explain.)

  • When hit-testing to see which layer was touched, I had to do both [touch locationInView:view] and [view convertPoint:location toView:nil]. However, when handling touch-moves, I only have to use [touch locationInView:view]. I don't understand why the coordinate systems are (apparently) different.

Coordinate Systems

Thanks for your comment about the different coordinate systems for different device orientation. Had spent lots of time figuring out why I couldn't tap the correct object.

Thanks again!

Saving button position when app terminates

Hi,

It would be interesting to 'save' the position of the buttons so that the next time the app loads, everything is where the user left it.

Any ideas of how you would implement this feature?

UIImage for tiles?

This looks great and I'm going to start experimenting tonight. But perhaps you know the answer before I pull out too much hair. I'd like to modify this to display images (UIImage objects). From a quick look at the code I think I can replace the CAGradientLayers (and not do the gloss manipulation & drawing), but if you have any advice I'd appreciate it.

This is a great example!

I think this is a great example, thanks. Could you provide any insight on using multiple UIViews in interface builder to construct the grid? Similar to the other post "I'd like to modify this to display images (UIImage objects)", but using UIViews. Thanks in advance for any additional help.

Yes, you can create a layer

Yes, you can create a layer and set the contents property to whatever image you want.

Landscap issue

Hello, i have create springborad view like same as , like wiggling,icon arrangement. its working fine when application launch potriate view but when i rotate in Landscan view it display perfectly but frame not set perfectly;

may be portrait and landscape frame are different. i have set Row = 6;Column = 5; in potrait mode and Landscape mode i have set Row = 7;Column = 6;

-(void)GridViewIcon {

[gridView.layer removeFromSuperlayer];
arrayIcon = [[NSMutableArray alloc]init];
NSArray *array = [[NSArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",.. 26 icon,nil];

arrayIcon = [NSMutableArray arrayWithArray:array];
[array release];

IconCount = [arrayIcon count];
k = 0;

gridView = [[UIView alloc]init];
//[gridView setUserInteractionEnabled:NO];

int gridH,gridW;
for (int row = 0; row <Row; ++row)
{
for (int col = 0; col < Column ; ++col)
{

int index = (row * Column) + col;

CGRect frame = CGRectMake(TILE_MARGIN + col * (TILE_MARGIN + TILE_WIDTH), TILE_MARGIN + row * (TILE_MARGIN + TILE_HEIGHT),
TILE_WIDTH, TILE_HEIGHT);

NSString *APPICON = [arrayIcon objectAtIndex:index];
UIImage *aImage = [UIImage imageNamed:APPICON];

WiggleEffect *objWiggle;
tileFrame[index] = frame;
objWiggle = [[WiggleEffect alloc]init];
objWiggle.tileIndex = index;
tileForFrame[index] = objWiggle;
objWiggle.frame = frame;

objWiggle.backgroundColor = [UIColor colorWithPatternImage:aImage].CGColor;
objWiggle.delegate = self;

[gridView.layer addSublayer:objWiggle];

[objWiggle setNeedsDisplay];
[objWiggle release];

k++;

if(k == arrayIcon.count)
{
[self.view addSubview:gridView];
return;
}
gridW = col * (TILE_MARGIN + 90) + 90;
gridH = (row + 1)*(TILE_MARGIN + 90 ) + 90;

}

gridView.frame= CGRectMake(0, 0, gridW, gridH);
gridView.center=self.view.center;

}

[self.view addSubview:gridView];

}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

touchStartTime = [event timestamp];

//[touches performSelector:@selector(longTap:) withObject:nil afterDelay:1.5];

if(isMoveable)
{

CALayer *hitLayer = [self layerForTouch:[touches anyObject]];
if ([hitLayer isKindOfClass:[WiggleEffect class]])
{

WiggleEffect *tile = (WiggleEffect*)hitLayer;
//NSInteger inte = tile.tileIndex;
heldTile = tile;
touchStartLocation = [[touches anyObject] locationInView:gridView];
heldStartPosition = tile.position;
//titleSelect = tile.tileIndex;

titleSelect = tile.messageTypeId;
heldFrameIndex = [self frameIndexForTileIndex:tile.tileIndex];

[tile moveToFront];
[tile appearDraggable];
}

}
CALayer *hitLayer = [self layerForTouch:[touches anyObject]];
if ([hitLayer isKindOfClass:[WiggleEffect class]])
{
WiggleEffect *tile = (WiggleEffect*)hitLayer;
//titleSelect = tile.tileIndex;
titleSelect = tile.messageTypeId;
}
else
{
titleSelect = 0;
}

}

  • (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {

    //NSLog(@" Touch touchesMoved at %d",[event timestamp]);
    if (heldTile)
    {
    UITouch *touch = [touches anyObject];
    UIView *view = gridView;
    CGPoint location = [touch locationInView:view];
    [self moveHeldTileToPoint:location];
    [self moveUnheldTilesAwayFromPoint:location];
    }
    }

  • (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {

    // Calculate how long touch lasted
    NSTimeInterval touchTimeDuration = [event timestamp] - touchStartTime;
    //NSLog(@" Touch duration: %3.2f seconds",touchTimeDuration);
    if(touchTimeDuration == 0.00)
    {

    if (!isWoggleRunning)
    {
    //NSLog(@" Touch Began at %d",touchStartTime);
    isWoggleRunning = YES;
    isMoveable = YES;
    CALayer *hitLayer = [self layerForTouch:[touches anyObject]];
    if ([hitLayer isKindOfClass:[WiggleEffect class]])
    {
    //UIGestureRecognizer *obj;
    // obj = [[UILongPressGestureRecognizer alloc]init];

    WiggleEffect *tile = (WiggleEffect*)hitLayer;
    //NSInteger inte = tile.tileIndex;
    heldTile = tile;
    touchStartLocation = [[touches anyObject] locationInView:gridView];
    heldStartPosition = tile.position;
    //titleSelect = tile.tileIndex;
    titleSelect = tile.messageTypeId;

    heldFrameIndex = [self frameIndexForTileIndex:tile.tileIndex];

    [tile moveToFront];
    [tile appearDraggable];
    NSLog(@"PRESSED AT %d to START WIGGLE",heldFrameIndex);
    [self startTilesWiggling];

    }

    }
    else
    {
    isMoveable = NO;
    isWoggleRunning = NO;
    [self stopTilesWiggling];
    }

    }

    if (heldTile)
    {
    [heldTile appearNormal];
    heldTile.frame = tileFrame[heldFrameIndex];
    heldTile = nil;
    }

    CALayer hitLayer = [self layerForTouch:[touches anyObject]];
    if ([hitLayer isKindOfClass:[WiggleEffect class]])
    {
    WiggleEffect *tile = (WiggleEffect
    )hitLayer;
    //titleSelect = tile.tileIndex;
    titleSelect = tile.messageTypeId;
    }
    // [self stopTilesWiggling];
    }

  • (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    {
    // NSLog(@" Touch touchesCancelled at %d",[event timestamp]);
    [self touchesEnded:touches withEvent:event];
    }

Landscap issue

I am using like same as but i added extra functionlit, when i run application in potrarite mode it working fine and i get all title and perfect layer touch, but when i change orientation (Landscape) that time not working proper layer. here is the code please help me out. if it possible.

[gridView.layer removeFromSuperlayer];
arrayIcon = [[NSMutableArray alloc]init];
NSArray *array = [[NSArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",.. 26 icon,nil];

arrayIcon = [NSMutableArray arrayWithArray:array];
[array release];

IconCount = [arrayIcon count];
k = 0;

gridView = [[UIView alloc]init];
//[gridView setUserInteractionEnabled:NO];

int gridH,gridW;
for (int row = 0; row

Thank you so much!

You just saved me 3 days of work here since im new to the stuff and this is exactly what im looking for!
CAN I PURCHASE YOU A COFFEE OR SO? ANY BOOK AT AMAZONE?


Posted by incree

2011/07/20 19:30 2011/07/20 19:30
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/23

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

[JavaScript]둥근 모서리 jQuery plugin

http://jquery.malsup.com/corner/


Posted by incree

2011/05/13 00:00 2011/05/13 00:00
,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/16

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

http://code.google.com/p/jqueryrotate/



Example 1

Simply rotate an image

$("#img").rotate(45);
or
$("#img").rotate({angle:45});
or

Example 2

This is simple example that rotates image when user mouseover/mouseout object.

Mouseover arrow to see effect.
$("#img").rotate({ 
   bind
:
     
{
        mouseover
: function() {
            $
(this).rotate({animateTo:180})
       
},
        mouseout
: function() {
            $
(this).rotate({animateTo:0})
       
}
     
}
   
});

Example 3

Rotate image endlessly

var angle = 0;
setInterval
(function(){
      angle
+=3;
     $
("#img").rotate(angle);
},50);

Rotate image endlessly using recursive function

var rotation = function (){
   $
("#img").rotate({
      angle
:0,
      animateTo
:360,
      callback
: rotation
   
});
}
rotation
();

Rotate image endlessly using recursive function and custom easing (similar to example with simple endless rotation)

var rotation = function (){
   $
("#img").rotate({
      angle
:0,
      animateTo
:360,
      callback
: rotation,
      easing
: function (x,t,b,c,d){        // t: current time, b: begInnIng value, c: change In value, d: duration
         
return c*(t/d)+b;
     
}
   
});
}
rotation
();

Example 4

Animation rotate using easing from http://gsgd.co.uk/sandbox/jquery/easing/

(remember to also include <script> contains easing)

Click on arrow to see effect.
$("#img").rotate({ 
   bind
:
     
{
        click
: function(){
            $
(this).rotate({ angle:0,animateTo:180,easing: $.easing.easeInOutExpo })
       
}
     
}
   
});

Posted by incree

2011/05/02 11:39 2011/05/02 11:39
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/15

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

[iPhone]iPhone UIWebView multi tabbed browsing

출처 : http://kaiengelhardt.com/2011/03/19/iph ··· bview%2F


Let’s Jump Into the Code

Now go to the ExplorerViewController.h file and modify it to this :

#import <UIKit/UIKit.h>

@interface ExplorerViewController : UIViewController <UITextFieldDelegate, UIWebViewDelegate, UIActionSheetDelegate>{
    UITextField *urlField;
    UIBarButtonItem *refreshButton;
    UIBarButtonItem *backButton;
    UIBarButtonItem *forwardButton;
    UIBarButtonItem *bookMarksButton;
    UIActivityIndicatorView *loadingActivity;
    UIWebView *webView;
    UINavigationBar *navigationBar;
    NSMutableArray *webViews;
    UIPageControl *tabControl;
}

@property (nonatomic, retain) IBOutlet UITextField *urlField;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *refreshButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *backButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *forwardButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *bookMarksButton;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *loadingActivity;
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) IBOutlet UINavigationBar *navigationBar;
@property (nonatomic, retain) NSMutableArray *webViews;
@property (nonatomic, retain) IBOutlet UIPageControl *tabControl;

-(NSString*)repairURL:(NSString*)url;
-(IBAction)refreshWebView;
-(IBAction)goBack;
-(IBAction)goForward;
-(void)actualizeButtons;
-(IBAction)bookmarksButtonTapped;
-(IBAction)addBookmarkButtonTapped;
-(IBAction)addTab;
-(IBAction)closeTab;
-(IBAction)tabControlValueChanged;

@end

We define a couple of methods, such as addTab or closeTab and tabControlValueChanged.
We also define one IBOutlet for the UIPageControl and one NSMutableArray, that will hold all our tabs.

Now go to the ExplorerViewController.h file and make the following :
Synthesize the properties we’ve just declared :

@synthesize tabControl;
@synthesize webViews;

Release them in dealloc :

[webViews release];
[tabControl release];
tabControl = nil;
webViews = nil;

Then go to the viewDidLoad method and add the following :

webViews = [[NSMutableArray alloc] initWithCapacity:10];
[self.webViews addObject:webView];
tabControl.numberOfPages = [self.webViews count];
tabControl.hidesForSinglePage = false;

Here we create a new NSMutableArray for the tabs and pass our current webView into it.
Then we actualize the actualise the number of pages in the tabControl to the number of tabs.

Switching Between Tabs

Then go to the top of the file and paste in this code :

-(IBAction)tabControlValueChanged {
    CGRect rect = self.webView.frame;
    self.webView.delegate = nil;
    [self.webView removeFromSuperview];
    self.webView = [webViews objectAtIndex:tabControl.currentPage];
    [self.view addSubview:self.webView];
    self.webView.delegate = self;
    urlField.text = [[[[self webView]request] URL] absoluteString];
    self.webView.frame = rect;
    [self actualizeButtons];
}

This code is a little bit tricky.
First I thought, that I could say self.webView = [webViews objectAtIndex:tabControl.currentPage] , but that didn’t work. The webView did not change.
The code above is a little workaround for it.
We remove the webView from its super view and add the new webView to the view of our viewController.
Note that we are setting the frame of the new webView to the frame of the current webView.
We also have to set the delegate of the current webView to nil and the delegate of the new webView to self.
Because we are changing the webView the current url changes too.
Therefore we have to set the text of the urlField to the url of the newTab.

This code is a little bit useless if we cannot add tabs.

Adding Tabs

Here’s the implementation of the addTab method :

-(IBAction)addTab {
    UIWebView *newTab = [[UIWebView alloc] initWithFrame:self.webView.frame];
    self.webView.delegate = nil;
    newTab.autoresizingMask = self.webView.autoresizingMask;
    newTab.scalesPageToFit = true;
    self.webView = newTab;
    self.webView.delegate = self;
    [webViews addObject:self.webView];
    tabControl.numberOfPages = [webViews count];
    tabControl.currentPage = tabControl.numberOfPages;
    urlField.text = @"";
    [newTab release];
    [self tabControlValueChanged];
    [urlField becomeFirstResponder];
}

First we create a new UIWebView, that is called newTab.
Then we set the delegate of the current webView to nil and set some default behavior of the newTab, such as the AutoResizingMask.
The AutoResizingMask says the webView how it should resize if the orientation is changed.
Do you remember, what we were doing in the last tutorial to define the resizing behavior of the webView?
We were setting the springs & struts in the Interface Builder.
What we do here is just copying the from the current webView to the newTab.
After that we set the current webView to the newTab and set the delegate of it to self.
After that we add the newTab to the webViews array.
The we actualise the number of pages in the tabControl and set its current page to the number of the new tab.
Finally we clear the urlField and let it become the first responder.
Note that we are calling the tabControlValueChanged method from inside of this method.
This is to switch directly to the new tab.

Closing Tabs

Now there is only one thing left : The closeTab method.
Paste these lines above the addTab method :

-(IBAction)closeTab {
    if (!(tabControl.numberOfPages <=1)) {
        int position = tabControl.currentPage - 1;
        if (position < 0) {
            position = 0;
        }
        [webViews removeObjectAtIndex:tabControl.currentPage];
        tabControl.currentPage = position;
        [self tabControlValueChanged];
        self.tabControl.numberOfPages--;
    }
}

This code is mostly self explaining.
We remove the current tab and show the tab that comes before the current tab.
If there is only one tab, nothing should happen.

Save everything in here and go back to the Interface Builder.

The Finishing Touches

Click on the page control and set the springs and struts to the following :

Then click on the addTab button and set them to this :

Finally click on the closeTab button and set them to this :

Then connect the valueChanged event of the page control with the tabControlValueChanged method and the touchUp event of the addTab- and closeTabButton with the addTab and the closeTab method.

Save everything and run your project.
It should work perfectly now.
Here’s is video showing it :

Tutorial Ending

Yeaaah!!!
Our web browser is more than complete.
You can be proud of you, because you made a complete browser, that can compete with Safari.
I hope you’ve enjoyed this tutorial and I’m glad that you are coming to my website.
In the next tutorial I think of making a video player or showing you how to take photos in your app.

Happy programming and god bless.

Here is the complete Xcode project with all the code we’ve developed in this tutorial series : Explorer Final Version with Tab Feature

Posted by incree

2011/04/10 18:57 2011/04/10 18:57
,
Response
0 Trackbacks , 1 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/12

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

« Previous : 1 : ... 9 : 10 : 11 : 12 : 13 : 14 : Next »

Notices

Archives

Authors

  1. incree

Recent Trackbacks

Calendar

«   2017/12   »
          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            

Site Stats

Total hits:
435939
Today:
114
Yesterday:
230