[GitHub] svn client


 

GitHub is already support svn client now.

https://github.com/blog/626-announcing-svn-support

Linux底下的endpoint/頻寬測試


作網路頻寬測試時,有的人會直接用 iperf/netAngel 做測試,不過其實Chariot/QCheck也是官方的一個選擇。以下以Ubuntu 9.04作為endpoint安裝與頻寬測試的例子。

Client Side

  • 要裝endpoint,請由此下載http://www.netiq.com/support/pe/upgrade.asp
  • Linux版的下載後解tar,直接跑
    ./endpoint.install 就會幫你裝好。
  • 裝好後default是直接啟動,重新啟動的話用
    /usr/local/NetIQ/endpoint restart &

Server Side

  • 要裝Chariot/QCheck,由http://www.ixchariot.com/下載。
  • 下面說明Chariot的步驟。
  • 安裝並啟動Chariot:Start/IxChariot/IxChariotConsole/File/New
  • (1) 指定你需要的pair數 (2)endpoint address (3)測試的Script

兩端都指定好了之後在 Chariot 按個 Run 就能知道你的頻寬了。

設定時間跑 Chariot  時間。 Run/Set Run Option…

image

 

如果沒法打Chariot的話,以下幾個原因提供參考:

  • Chariot和endpoint版本不合。
  • 防火牆擋住了,可以暫時先把防火牆關掉。

如果可以的話,可在Shield room和開放空間作測試並比較。

[HyperTerminal]


 

How to install the WinXP HyperTerminal client on Windows Vista or Windows 7 [FREE]?

[MultiSkypeLauncher]


MultiSkypeLauncher

[Hub] A Passive Ethernet Hub


市面上的 Hub 幾乎是 Switch 了,若只要單純 Hub 功能的話

  1. 自行製作,參考 A Passive Ethernet Hub
  2. 購買有 mirror port 的 Switch

[Mail] Live Mail 2011


新公司用的 yahoo! smallbusiness 的服務。使用時要先有一個Yahoo信箱

如果要用 Microsoft Live Mail 收信的話,要做以下設定

pop3/smtp設定,

  • 內送郵件: pop.bizmail.yahoo.com
  • 外寄郵件: smtp.bizmail.yahoo.com
  • 電子郵件使用者名稱: 這邊使用公司配的 email address

更改檔案夾

  • 預設位置在 C:\Users\ouner\AppData\Local\Microsoft\Windows Live Mail
  • 點選快速存取工具列
    image
  • 選項/郵件/進階/維護
    image
  • 郵件檔資料夾
    image
  • 中間省略,變更完之後就會開始複製。
    image

SNMP


 

SNMPTrap

SNMT+MRTG

libsmi - A Library to Access SMI MIB Information

SNMP網路管理程序

Yale 系統程式監控


 

Yale

【Fast IP Changer】快速切換IP


有兩種選擇

  • Fast IP Changer 可以偵測到無線網卡
  • IPChanger 無法偵測到無線網卡

【yED】Graph Editor


yED

Operation

Reference

【DD-WRT】WHR-HP-G300N


Hardware

  • WHR-HP-G300N
    Costco Ntd$1399.

Firmware

Function

  • IP 192.168.11.1
  • uname –av
    Linux DD-WRT 2.6.24.111 #3402 Sat Aug 7 04:02:02 CEST 2010 mips unknown
  • cat /proc/cpuinfo

    system type             : Atheros AR7240 rev 1.2 (0x00c2)
    processor               : 0
    cpu model               : MIPS 24K V7.4
    BogoMIPS                : 266.24
    CPUClock                : 400
    wait instruction        : yes
    microsecond timers      : yes
    tlb_entries             : 16
    extra interrupt vector  : yes
    hardware watchpoint     : yes
    ASEs implemented        : mips16
    shadow register sets    : 1
    VCED exceptions         : not available
    VCEI exceptions         : not available

  • cat /proc/mtd

    dev:    size   erasesize  name
    mtd0: 00040000 00010000 "RedBoot"
    mtd1: 003a0000 00010000 "linux"
    mtd2: 002b4000 00010000 "rootfs"
    mtd3: 00030000 00010000 "ddwrt"
    mtd4: 00010000 00010000 "nvram"
    mtd5: 00010000 00010000 "board_config"
    mtd6: 00400000 00010000 "fullflash"
    mtd7: 00040000 00010000 "fullboot"

  • cat /tmp/dnsmasq.conf

    interface=br0
    resolv-file=/tmp/resolv.dnsmasq
    dhcp-leasefile=/tmp/dnsmasq.leases
    dhcp-lease-max=64
    dhcp-option=lan,3,192.168.11.1
    dhcp-authoritative
    dhcp-range=lan,192.168.11.2,192.168.11.65,255.255.255.0,1440m
    stop-dns-rebind

  • ps

    PID USER       VSZ STAT COMMAND
       1 root       940 S    /sbin/init
       2 root         0 SW<  [kthreadd]
       3 root         0 SW<  [ksoftirqd/0]
       4 root         0 SW<  [events/0]
       5 root         0 SW<  [khelper]
      39 root         0 SW<  [kblockd/0]
      58 root         0 SW   [pdflush]
      59 root         0 SW   [pdflush]
      60 root         0 SW<  [kswapd0]
      61 root         0 SW<  [aio/0]
    589 root         0 SW<  [mtdblockd]
    610 root      1332 S    watchdog
    691 root      1296 S    resetbutton
    933 root       916 S    telnetd
    949 root       576 S    cron
    950 root       676 S    dnsmasq --conf-file=/tmp/dnsmasq.conf
    951 root       572 S    udhcpc -i eth0 -p /var/run/udhcpc.pid -s /tmp/udhcpc
    959 root       940 S    ttraff
    1162 root      2260 S    httpd -p 80
    1247 root       936 S    -sh
    1263 root      1012 S    process_monitor
    1619 root       916 R    ps

  • http
    cmd: httpd -p 80
  • Telnet (default on)
    telnet 192.168.11.1
  • Multi-SSID(Virtual Interface)

Reference

【Wifi】Tools


Packet Sniffer/Thruput/Radius

Packet Sniffer

  • Windows/Linux: ethereal
  • Windows only: netmon
  • Linux consoal mode: tcpdump

802.11 Packet Sniffer

Windows

Thruput check/endpoint

Access pointer monitor:

Stable Testing

  • 台灣國道高速公路交通即時路況影像 http://www.nfreeway.gov.tw/
  • Hichannel節目(球賽...)
  • SpeedTest
  • FTP download/Http download
  • Netlimiter

Channel(11g)

Power Saving

  •   let’s nb into power saving mode

Driver

  • Atheros: madwifi
  • Ralink
  • Boardcom

SuperG

  • Turbo G and dynamic
  • Turbo G and static ...

Wifi alliance

Radius server(WPA-Enterprise)

Instrument

【OmniPeek】抓封包


image

首先你需要準備下面的硬體和軟體

【硬體】

可以抓封包的網卡,有

  • D-Link DWA-140(chipset rt2870,11n draft)
  • D-Link DWA-160 AG2(Atheros USB 802.11n Wireless LAN card)
    ps. hardware version B is ralink soluction.

【軟體】 

  • OmniPeek,目前我所使用的版本是5.0。
  • Driver,這個和我們一般用的driver是不一樣的,可以上 http://www.wildpackets.com/ 
    • rt2870 上 Ralink 網站 下載(OmniPeek_2870.zip),rt2870.inf/rt2870.sys。
    • dwa-160 driver 內附 omnipeek.
      C:\Program Files\WildPackets\OmniPeek Demo\Drivers\Atheros\Atheros_USB_3.0\x86
  • 之前若有裝過不是抓封包的Driver記的先移除,重開機插卡之後如果沒跳出安裝Driver的視窗
    請直接用*.inf 安裝。

【使用】

  • 打開OmniPeek
    image
  • 選 New Capture
    image 
  • 若是 DWA-140 指定網卡,設成RT2870。
    image
  • AdapterFilters(先把802.11 Beacons打勾做測試),就會看到封包進來囉。
  • 補充,如果對AP的profile不了解(如SSID/Channel/加密方式…),可以先登入AP查詢。
    image
  • 可以先從Beacons查看/比對封包的一些性質,比如BSSID/是否加密。
  • Filters可以用許多組合,可先嘗試用兩台電腦互ping來抓兩端ICMP的封包。
  • 建議先把 Channel 設死(別用auto),比較好抓。
  • 如果你不想設定一堆filter條件的話,建議在類似shield room的環境測試會更好。
【參考】

【inSSIDer 2】network scanner


 

NetStumbler 替代品。

【Lenovo】ThinkPad X31


 

換電容

附件

【iOS】iPhone Developer Program


 

  • 按照 iPhone Developer Program Enroll
  • 按照接下來頁面依序填入申請資料,以下省略。
  • 經過兩三天左右會收到信用卡帳單。

Troubleshoot

  • 收到帶有 Activation Code 點選連結之後卻  Enroll 失敗
    • 登入後在右方看到提示,點選 form
      image
    • 填入
      • Enrollment ID
        點選帶有 Activation Code 的 Email 就可以看到
        image
      • Email address
      • Notarization or Solicitor Certification Stamp
        這邊我是用駕照
    • Fax to Number +1 (408) 862-1519
      • 由於我沒有傳真機,所以採用 PamFax  的服務,註冊後會送 NT$11.49。
        提供 網頁版 或 Mac 版工具與 信用卡或Skype付款機制。
        image
      • 此次發送會耗費 NT$6.38。
      • 成功會經由 Email 通知。
    • 經過兩三天左右會收到通知進行再認證
      image
    • 登入 Member Center 會通知你進行下一步
      image
    • 完成認證
      image
    • 最後會在收到幾封信,跟著他要求的進行。
    • 登入 iTunes Connect 即可進行管理。

【JOB】工作用語


Date

  1. Date of Separation 離職日
  2. Date of Employment 到職日

Skill

  1. Driving License of Automobile 汽車駕照

Military experience

Work experience

  • Reason for leaving
  • Career growth
  • Enhanced Education

Reference

【週邊】HP Color LaserJet CM1312 MFP


image

HP Color LaserJet CM1312 MFP Series PCL6

【軟體與驅動程式】

  • 隨機光碟,這款機器有主要的三片光碟/軟體:
    • for Mac: HP Director(支援掃描)
    • for Windows: HP Digitial Imaging Monitor
    • for  Mac/Win: Readiries 影像辨認軟體
  • 雖有隨機光碟,不過也可由 HP 網站下載驅動,請由 支援及驅動程式 進入,
    產品名稱為 HP Color LaserJet CM1312 Multifunction Printer

【列印方式】

  • 按照一般的方式操作。

【掃描方式】

掃描在Windows底下兩個方法:
  1. 方法一
    1. 打開 HP Digitial Imaging Monitor
    2. 啟動活動/ 掃描圖片...
  2. 方法二
    1. 打開 我的電腦,會出現掃描器的裝置,點兩下帶起Windows內建的掃描軟體。
      (20110915update: 在 Win7 需由 開始/所有程式/Windoes傳真與掃描)

Mac環境使用 HP Director

  1. 可以使用 Scan/Scan to foldeer
    image
  2. 如果有需要多張圖片檔合成一張 可使用
    Adobe Acrobat X Pro/Create/Combine file into single pdf

【維護】

  • 校正
    校正直接使用印表機上面的控制面板,使用 設定|系統設定|列印品質|校準色彩|立即校準
  • 耗材報告(可簡單的用來檢視校準後的結果):
    直接使用印表機上面的控制面板,使用 設定|報告|耗材報告頁
  • 其他還有展示頁功能,請直接由控制面板進入。

【耗材碳粉】

  1. 黑色的採用 CB540A,同時適合 CP1215/LP1518/CM1312
  2. 彩色目前還沒換過。

【客服專線】

【參考】

【Paper】IEEE 802.11


研究中

IEEE802.16Mesh網路之QoS相關機制研究與設計

在IEEE 802.11網路下的快速換手機制:IEEE 802.11F與IEEE 802.11r

【PHP】Parse HTML


參考看看 Parse an HTML Table with PHP

【PHP】Sqlite3


網路都找到的一些都有一點小問題 整理後的範例

$dsn = 'sqlite:sql.db';
try{
    $dbh = new PDO($dsn, $user, $password);
    echo 'PDO Connection Ok',"\n";
    $dbh->exec("CREATE TABLE PKU(id integer,name varchar(255))");
    echo 'Create Table ok',"\n";
    $dbh->exec("INSERT INTO PKU values(1,'jarjin')");
    echo 'Insert Data ok',"\n";
    $dbh->beginTransaction();
    $sth = $dbh->prepare('SELECT *FROM PKU');
    $sth->execute();
    $result = $sth->fetchAll();
    print_r($result);
    $dsn=null;
    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
        $dsn=null;
    }

參考 sqlite php5 PDO

【Mac】簡轉繁


Mac 在服務內以內建, 打開一個編輯器(如BBEdit) , 選取要轉換的片段, 選擇左上邊 Toolbar/服務/轉換 即可.

【PHP】Big5 to Unicode


本來想用 Perl 寫, 可惜 Text::Iconv 還要裝, 所以改用現成的 PHP 來做.

<?
$url = "http://www.xxx.com/index.html";
$contents = file_get_contents($url);
//如果出現中文亂碼使用下面代碼
//$getcontent = iconv("big5", "utf-8",file_get_contents($url));
//echo $getcontent;
echo $contents;
?>

參考

【iOS】UIToolbar


 

  • 初始化

    IBOutlet UIToolbar    *toolbar;

    //create toolbar using new
    toolbar = [UIToolbar new];
    toolbar.barStyle = UIBarStyleDefault;
    [toolbar sizeToFit];
    toolbar.frame = CGRectMake(0, 410, 320, 50);

    //Add buttons
    UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                                                 target:self
                                                                                 action:@selector(pressButton1:)];

    UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                                                 target:self
                                                                                 action:@selector(pressButton2:)];

    UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
                                                                                 target:self
                                                                                 action:@selector(pressButton3:)];

    //Use this to put space in between your toolbox buttons
    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                              target:nil
                                                                              action:nil];

    //Add buttons to the array
    NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil];

    //release buttons
    [systemItem1 release];
    [systemItem2 release];
    [systemItem3 release];
    [flexItem release];

    //add array of buttons to toolbar
    [toolbar setItems:items animated:NO];

    [self.view addSubview:toolbar];

  • style

    typedef enum {
        UIBarButtonSystemItemDone,
        UIBarButtonSystemItemCancel,
        UIBarButtonSystemItemEdit, 
        UIBarButtonSystemItemSave, 
        UIBarButtonSystemItemAdd,
        UIBarButtonSystemItemFlexibleSpace,
        UIBarButtonSystemItemFixedSpace,
        UIBarButtonSystemItemCompose,
        UIBarButtonSystemItemReply,
        UIBarButtonSystemItemAction,
        UIBarButtonSystemItemOrganize,
        UIBarButtonSystemItemBookmarks,
        UIBarButtonSystemItemSearch,
        UIBarButtonSystemItemRefresh,
        UIBarButtonSystemItemStop,
        UIBarButtonSystemItemCamera,
        UIBarButtonSystemItemTrash,
        UIBarButtonSystemItemPlay,
        UIBarButtonSystemItemPause,
        UIBarButtonSystemItemRewind,
        UIBarButtonSystemItemFastForward,
    #if __IPHONE_3_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
        UIBarButtonSystemItemUndo,
        UIBarButtonSystemItemRedo,
    #endif
    #if __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
        UIBarButtonSystemItemPageCurl,
    #endif
    } UIBarButtonSystemItem;

  • Type 初始化, 提供 Custom/RoundedRect/Detail/Info/ContactAdd, 使用 Custom 時記得要給 Frame

    UIButton* button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button3 addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [button3 setTitle:@"+" forState:UIControlStateNormal];
    [button3 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    button3.titleLabel.font = [UIFont systemFontOfSize:25];
    button3.frame = CGRectMake(100, 170, 100, 30);

    // create button item -- possible because UIButton subclasses UIView!
    UIBarButtonItem *systemItem3=[[UIBarButtonItem alloc] initWithCustomView:button3];

  • type

    typedef enum {
        UIButtonTypeCustom = 0,
        UIButtonTypeRoundedRect,
        UIButtonTypeDetailDisclosure,
        UIButtonTypeInfoLight,
        UIButtonTypeInfoDark,
        UIButtonTypeContactAdd,
    } UIButtonType;

【Mac】gif2apng


不想裝 Imagemagick 可以直接試試輕巧的 gif2apng
雖然官網有提示如何批次轉換,但卻無法成功。以下提供另一個方式。

for img in *.gif; do
    filename=${img%.*}
    gif2apng "$filename.gif" "$filename.png"
done

參考

【Mac】SiteSucker


SiteSucker 是 mac 版的 Teleport。可由 App Store 下載。

image

【Mac】cscope


參考 https://anylinux.net/post/2453.html

【iOS】Shortcuts for XCode 4


  • Command + Enter
    Command + Option + Enter

【iOS】Animations


 

  • AnimationCurve
    - UIViewAnimationCurveEaseIn
    - UIViewAnimationCurveEaseInOut
    - UIViewAnimationCurveEaseOut
    - UIViewAnimationCurveLinear
  • AnimationTransition
    - UIViewAnimationTransitionCurlUp
    - UIViewAnimationTransitionFlipFromRight
    - UIViewAnimationTransitionFlipFromLeft
  • 基本框架

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
                           forView:self.view cache:YES];

    // Action

    [UIView commitAnimations];

  • 框架範例二

    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [self.view.layer addAnimation:animation forKey:nil];

    //do something here

    [CATransaction commit];

【iOS】Keyboard


 

  • 讓 TextField 所帶出的 Keyboard 消失

    - (IBAction) textFieldReturn:(id)textField
    {
        [textField resignFirstResponder];
    }

【iOS】Plist 存取


 

  • 參考 Property List Tutorial – using plist to store user data, 以下截取重要部分.
  • 建立 Data.plist 放在 Resources 底下
    image
  • 宣告

    @interface PlistTutorialViewController : UIViewController
    {
        IBOutlet UITextField    *nameEntered;
        IBOutlet UITextField    *homePhone;
        IBOutlet UITextField    *workPhone;
        IBOutlet UITextField    *cellPhone;
       
        NSString        *personName;
        NSMutableArray    *phoneNumbers;
    }

    @property (nonatomic, retain)    UITextField        *nameEntered;
    @property (nonatomic, retain)    UITextField        *homePhone;
    @property (nonatomic, retain)    UITextField        *workPhone;
    @property (nonatomic, retain)    UITextField        *cellPhone;

    @property (nonatomic, retain)    NSString        *personName;
    @property (nonatomic, retain)    NSMutableArray    *phoneNumbers;

    - (IBAction) saveData;
    - (IBAction) textFieldReturn:(id)textField;

  • 讀取

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Data.plist code
        // get paths from root direcory
        NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
        // get documents path
        NSString *documentsPath = [paths objectAtIndex:0];
        // get the path to our Data/plist file
        NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
       
        // check to see if Data.plist exists in documents
        if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
        {
            // if not in documents, get property list from main bundle
            plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
        }
       
        // read property list into memory as an NSData object
        NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
        NSString *errorDesc = nil;
        NSPropertyListFormat format;
        // convert static property liost into dictionary object
        NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                              propertyListFromData:plistXML
                                              mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                              format:&format
                                              errorDescription:&errorDesc];
        if (!temp)
        {
            NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
        }
        // assign values
        self.personName = [temp objectForKey:@"Name"];
        self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
        // display values
        nameEntered.text = personName;
        homePhone.text = [phoneNumbers objectAtIndex:0];
        workPhone.text = [phoneNumbers objectAtIndex:1];
        cellPhone.text = [phoneNumbers objectAtIndex:2];
    }

  • 寫入

    - (IBAction) saveData
    {
        // get paths from root direcory
        NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
        // get documents path
        NSString *documentsPath = [paths objectAtIndex:0];
        // get the path to our Data/plist file
        NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
       
        // set the variables to the values in the text fields
        self.personName = nameEntered.text;
        self.phoneNumbers = [[NSMutableArray alloc] initWithCapacity:3];
        [phoneNumbers addObject:homePhone.text];
        [phoneNumbers addObject:workPhone.text];
        [phoneNumbers addObject:cellPhone.text];
       
        // create dictionary with values in UITextFields
        NSDictionary *plistDict = [NSDictionary
                                   dictionaryWithObjects:
                                   [NSArray arrayWithObjects: personName, phoneNumbers, nil]
                                   forKeys:[NSArray arrayWithObjects: @"Name", @"Phones", nil]];
       
        NSString *error = nil;
        // create NSData from dictionary
        NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict
                                                                       format:NSPropertyListXMLFormat_v1_0
                                                             errorDescription:&error];
       
        // check is plistData exists
        if(plistData)
        {
            // write plistData to our Data.plist file
            [plistData writeToFile:plistPath atomically:YES];
        }
        else
        {
            NSLog(@"Error in saveData: %@", error);
            [error release];
        }
    }

【iOS】fmdb


fmdb, 更加簡化 Sqlite 的操作.

【iOS】CustomBadge


CustomBadge

  • 範例, 顯示兩個 Badge, 或可以說是一個, 技巧就是把一個疊在另一個上面.
    image

    CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2"
                                                       withStringColor:[UIColor whiteColor]
                                                        withInsetColor:[UIColor redColor]
                                                        withBadgeFrame:YES
                                                   withBadgeFrameColor:[UIColor whiteColor]
                                                             withScale:1.0
                                                           withShining:YES];
    CustomBadge *customBadge2 = [CustomBadge customBadgeWithString:@"CustomBadge"
                                                       withStringColor:[UIColor blackColor]
                                                        withInsetColor:[UIColor greenColor]
                                                        withBadgeFrame:YES
                                                   withBadgeFrameColor:[UIColor yellowColor]
                                                             withScale:1.5
                                                           withShining:YES];
        
    [customBadge1 setFrame:CGRectMake(self.view.frame.size.width/2-customBadge1.frame.size.width/2+customBadge2.frame.size.width/2, 110, customBadge1.frame.size.width, customBadge1.frame.size.height)];
    [customBadge2 setFrame:CGRectMake(self.view.frame.size.width/2-customBadge2.frame.size.width/2, 110, customBadge2.frame.size.width, customBadge2.frame.size.height)];

        [self.view addSubview:customBadge2];
        [self.view addSubview:customBadge1];

【iOS】UISegmentedControl


  • 初始

        UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:
                                       [NSArray arrayWithObjects: @"Mail", @”SMS”, nil]];
        segment.frame =  CGRectMake(10, 10, 200, 35);
        segment.selectedSegmentIndex = NSIntegerMax;
        segment.tag = 3;
        [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
        segment.segmentedControlStyle = UISegmentedControlStyleBar;
        [self.view addSubview:segment];

  • 加入 badge,  要搭配 CustomBadge
    image

    - (IBAction) segmentAction:(id)sender
    {
        UISegmentedControl *segment = (UISegmentedControl*) sender;
        NSLog(@"UIControlEventValueChanged:%d", segment.selectedSegmentIndex);
        segment.enabled = NO;
    }
    - (void) viewDidLoad
    {

        UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:
                                       [NSArray arrayWithObjects: @"Mail", @"SMS", nil]];
        segment.frame =  CGRectMake(10, 10, 200, 35);
        segment.selectedSegmentIndex = NSIntegerMax;
        segment.tag = 3;
        [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
        segment.segmentedControlStyle = UISegmentedControlStyleBar;
        [self.view addSubview:segment];
       
        CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"32"
                                                       withStringColor:[UIColor whiteColor]
                                                        withInsetColor:[UIColor greenColor]
                                                        withBadgeFrame:YES
                                                   withBadgeFrameColor:[UIColor whiteColor]
                                                             withScale:1.0
                                                           withShining:YES];       
       
        [customBadge1 setFrame:CGRectMake(90, 0, 20, 20)];
        [self.view addSubview:customBadge1];
       
        CustomBadge *customBadge2 = [CustomBadge customBadgeWithString:@"33"
                                                       withStringColor:[UIColor whiteColor]
                                                        withInsetColor:[UIColor redColor]
                                                        withBadgeFrame:YES
                                                   withBadgeFrameColor:[UIColor whiteColor]
                                                             withScale:1.0
                                                           withShining:YES];       
       
        [customBadge2 setFrame:CGRectMake(190, 0, 20, 20)];
        [self.view addSubview:customBadge2];

        [self.view bringSubviewToFront:customBadge1];
        [self.view bringSubviewToFront:customBadge2];
        }

【iOS】UISwitch


  • 初始化

    UISwitch *switch= [ [ UISwitch alloc ] initWithFrame: CGRectMake(200, 10, 0, 0) ];
    switch.on = NO;
    switch.tag = 2;
    [switch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    [self addSubview: jumpToNextAuto];

  • 縮小要用 transform
    switch.transform = CGAffineTransformMakeScale(0.75, 0.75);

【iOS】UIImage


 

【iOS】UITabBar


 

  • 屬於 Bar  的有
    - Navigation bars
    - Toolbars
    - Tabbars
  • Style/Image 可透過

    - (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag;
    - (id)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag;

  • Style

    typedef enum {
        UITabBarSystemItemMore,
        UITabBarSystemItemFavorites,
        UITabBarSystemItemFeatured,
        UITabBarSystemItemTopRated,
        UITabBarSystemItemRecents,
        UITabBarSystemItemContacts,
        UITabBarSystemItemHistory,
        UITabBarSystemItemBookmarks,
        UITabBarSystemItemSearch,
        UITabBarSystemItemDownloads,
        UITabBarSystemItemMostRecent,
        UITabBarSystemItemMostViewed,
    } UITabBarSystemItem;

  • TabBar icon 大小
    32 x 32 png 背景為透明。
  • TabBar icon 作圖,參考
    How to Draw Pixel-Perfect iPhone Toolbar Icons
    Generating icons for iPhone UITabBar
    tabbaritem的png無法顯示
  • 顯示圖片設定,實際顯示的圖片會便

    UIImage* aImage = [UIImage imageNamed:@"favorites.png"];
    [self.tabBarItem setImage:aImage];

  • 內建直接設定 badge,後面帶入 NSString
    [self.tabBarItem setBadgeValue:@"100"];
  • 承上面兩項,實際顯示的圖形會被系統再處理一次
    原本 被選取時 沒被選取時
    image
    32 x 32
    image image

【iOS】UIGestureRecognizer


有兩種方式 (TBD)

  • UIResponder的四種方法,可以讓使用者自行設計手勢
    - (void)touch esBegan:(NSSet *)touches withEvent:(UIEvent *)event
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
     
  • UIGestureRecognizer的方式,不用再自己一個一個去設計/解析,目前有6種
    - UILongPressGestureRecognizer
    - UIPanGestureRecognizer
    - UIPinchGestureRecognizer
    - UIRotationGestureRecognizer
    - UISwipeGestureRecognizer
    - UITapGestureRecognizer
  • 第一種方式的用法
    參考 iOS: how do you get the touchesBegan coordinates when a UIButton is triggered? 

    UIButton *mouse = [UIButton buttonWithType:UIButtonTypeCustom];
    [mouse setFrame:CGRectMake(90.0f, 55.0f, 118.0f, 118.0f)];
    [mouse setBackgroundImage:[UIImage imageNamed:@"mouse.png"] forState:UIControlStateNormal];
    [mouse setTitle:@"Mouse" forState:UIControlStateNormal];
    [mouse.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
    [mouse setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [mouse addTarget: self action: @selector(mouseClick:) forControlEvents: UIControlEventTouchDown];
    [parent addSubview:mouse];

    [mouse addTarget:self action:@selector(touchesBegan:withEvent:)  forControlEvents: UIControlEventTouchDown];
    [mouse addTarget:self action:@selector(touchesMoved:withEvent:) forControlEvents: UIControlEventTouchDragInside];
    [mouse addTarget:self action:@selector(touchesEnded:withEvent:)  forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchUpOutside];

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"touchesBegan");
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint touchPoint = [touch locationInView:parent];
        NSLog(@"Touch x : %f y : %f", touchPoint.x, touchPoint.y);
    }

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"touchesMoved");
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint touchPoint = [touch locationInView:parent];
        NSLog(@"Touch x : %f y : %f", touchPoint.x, touchPoint.y);
        mouse.center = CGPointMake(touchPoint.x,touchPoint.y);
    }
    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"touchesEnded");
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint touchPoint = [touch locationInView:parent];
        NSLog(@"Touch x : %f y : %f", touchPoint.x, touchPoint.y);
    }

【iOS】UIScrollView


(tbd)

  • 組成要素
    - ContentSize
  • 搭配 UIPageControl 使用
    -  換頁

【iOS】NSTimer


在使用時可以先包一層比較方便

【iOS】NSArray/NSMutableArray


 

  • NSMutableArray新增
    addObject
  • NSMutableArray 移除
    removeObject/removeObjectAtIndex
  • 排序
    (tbd)
  • 二維陣列用兩個 NSArray/NSMutableArray 來組成,參考
    http://stackoverflow.com/questions/3261329/how-to-create-a-2d-nsarray-or-nsmutablearray-in-objective-c
    http://stackoverflow.com/questions/2583710/how-to-simplify-my-code-2d-nsarray-in-objective-c
  • 承上,也可以用 NSArray/NSMutableArray 搭配 NSDictionary/NSMutableDictionary 來組成。

【iOS】UILabel


UILabel

  • 初始化
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
  • 指定顯示內容
    [label setText:@"Default Gamepad"];
  • 字體指定與大小指定
    [label setFont:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
  • 字體顏色
    [label setTextColor:[UIColor lightTextColor]];
  • 字體背景顏色
    [label setBackgroundColor:[UIColor clearColor]];
  • 排版設定
    [label setTextAlignment:UITextAlignmentCenter];
  • Alpha值
    [label setAlpha:0.9f];

【iOS】AQGridView


雖然有 UITableView,但也只能將資料一一橫向顯示,如果要顯示Grid狀的資料,就需要透過第三方元件。

參考 https://github.com/AlanQuatermain/AQGridView

【iOS】UIButton


幾個重點 (tbd)
  • Button類型
    typedef enum {
       UIButtonTypeCustom = 0,
       UIButtonTypeRoundedRect,
       UIButtonTypeDetailDisclosure,
       UIButtonTypeInfoLight,
       UIButtonTypeInfoDark,
       UIButtonTypeContactAdd,
    } UIButtonType;
  • 注意採用 buttonWithType 的情況,
    - 宣告時有 alloc 的話,需要手動relase,例如
    button = [[UIButton alloc] init];
    - 若採用buttonWithType沒有使用alloc 的話,就不需要手動 release,否則在release時會crash。
    UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom]retain];
  • Selected 需要自行更改
    - 設定圖片
    [button setBackgroundImage:someImage forState:UIControlStateSelected];
    - 自行更改 status,就可以江圖片顯示出來。
    self.checkInButton.selected = YES;
  • 基本用法

    UIButton *mouse = [UIButton buttonWithType:UIButtonTypeCustom];
    [mouse setFrame:CGRectMake(90.0f, 55.0f, 118.0f, 118.0f)];
    [mouse setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
    [mouse setTitle:@"Mouse" forState:UIControlStateNormal];
    [mouse.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
    [mouse setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [mouse addTarget: self action: @selector(mouseClick:) forControlEvents: UIControlEventTouchDown];
    [parent addSubview:mouse];

  • 漸層UIButton需要以UIButton 擴展的第三方元件,或由美工直接做出底圖。
    參考 Custom UIButton without using any images
  • CustomBadge
    參考 CustomBadge 或 Three320/TTButton 也有範例。

    問題
    可以用 UISegmentedControl 做出漸層的按鈕,但不知如何 binding 事件
    http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem

【iOS】UIPopoverController


UIPopoverController

  • 不要箭頭,將 permittedArrowDirections 設成 0

    [self.popoverController presentPopoverFromBarButtonItem:anItem  
                                    permittedArrowDirections:0
                                                    animated:YES];

【iOS】UIView


UIView 兩三事。

  • 使用 hex 設成特殊色背景,可先用 Digital Color 測量器,取色後將值填入 UIColorFromRGB  

    #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

    [profileListPanel setBackgroundColor:UIColorFromRGB(0xDDDFE4)];

  • 製作圓角 UIView

    [aView setAlpha:0.9f];
    [[aView layer] setBorderWidth:4.0f];
    [[aView layer] setBorderColor:[UIColor clearColor].CGColor];
    [[aView layer] setMasksToBounds:YES];
    [[aView layer] setBackgroundColor:[UIColor clearColor].CGColor];
    [[aView layer] setCornerRadius:10.0f];

  • 對齊方式共有
    - UIViewAutoresizingNone
    - UIViewAutoresizingFlexibleWidth
    - UIViewAutoresizingFlexibleHeight
    - UIViewAutoresizingFlexibleTopMargin
    - UIViewAutoresizingFlexibleBottomMargin
    - UIViewAutoresizingFlexibleLeftMargin
    - UIViewAutoresizingFlexibleRightMargin
  • 有將視窗顯示出類似 UIPopoverController/UIToolBar 的需求(Framed Table),但一些邊框顏色有些許不同時, 中間也需自己調整高度的話,可以切成三張圖,分別利用三個UIImageView 來貼出背景圖。
    - dialogbox_bg_top (類似UIPopoverController 上半部,大小為 484x78)
    - dialogbox_bg_center ( 類似UIPopoverController 中間部 484x1 ,高度為 1 讓它可自行延展)
    - dialogbox_bg_end (類似UIPopoverController 下半部 484x78)

    UIImageView *imageViewTop = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dialogbox_bg_top.png"]];
    imageViewTop.frame = CGRectMake(0.0f, 0.0f, 484.0f, 78.0f);
    [aView addSubview: imageViewTop];
    [aView bringSubviewToFront:imageViewTop];
    [imageViewTop release];
    imageViewTop = nil;

    UIImageView *imageViewCenter = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dialogbox_bg_center.png"]];
    if (profilePurchased)
    {
    imageViewCenter.frame = CGRectMake(0.0f, 78.0f, 484.0f, WITHOUT_SOME_LAYOUT - (78.0f*2));
    }else {
    imageViewCenter.frame = CGRectMake(0.0f, 78.0f, 484.0f, 648.0f-78.0f*2);
    }

    [aView addSubview: imageViewCenter];
    [aView bringSubviewToFront:imageViewCenter];
    [imageViewCenter release];
    imageViewCenter = nil;

    UIImageView *imageViewEnd = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dialogbox_bg_end.png"]];
    if (profilePurchased)
    {
    imageViewEnd.frame = CGRectMake(0.0f, WITHOUT_SOME_LAYOUT - 78.0f, 484.0f, 78.0f);
    }else {
    imageViewEnd.frame = CGRectMake(0.0f, 648.0f - 78.0f, 484.0f, 78.0f);
    }   
    [aView addSubview: imageViewEnd];
    [aView bringSubviewToFront:imageViewEnd];
    [imageViewEnd release];
    imageViewEnd = nil;

  • 承上,這樣的話原本是在UIToolBar/UIBarButtonItem的就要自行貼入所需要的UIButton。範例如下

    UIImage *btnCancelImg = [UIImage imageNamed:@"dialog_btn_bg_black.png"];
    UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnCancel setAlpha:0.9f];
    [btnCancel setFrame:CGRectMake(12.0, 6.0, 50.0, 29.0)];
    [btnCancel setBackgroundImage:btnCancelImg forState:UIControlStateNormal];
    [btnCancel setTitle:@"Cancel" forState:UIControlStateNormal];
    [btnCancel.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12]];
    [btnCancel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnCancel addTarget: self action: @selector(doCancel:) forControlEvents: UIControlEventTouchDown];
    [aView addSubview:btnCancel];

  • 原本的顯示文字也要自行貼入,範例如下

    UILabel *aLabel = [[UILabel alloc]initWithFrame:CGRectMake(160.0f, 10.0f, 200.0f, 20.0f)];
    aLabel.text = @"Game Pad Rack";
    aLabel.textColor = [UIColor whiteColor];
    [aLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20.0f]];
    aLabel.backgroundColor = [UIColor clearColor];
    aLabel.font = [UIFont boldSystemFontOfSize:20.0f];
    [aLabel setBackgroundColor:[UIColor clearColor]];
    [aView addSubview:labGamePadRack];
    [aLabel release];

  • removeFromSuperview/
  • viewWithTag
  • 遞迴處理所有子視圖的方式
    for (UIView *subview in [aView subviews])
    {
    }
 

Ed32. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com