読者です 読者をやめる 読者になる 読者になる

Haruyuki Mohri

毛利春幸のブログです。

How to use the UIButton 10 Seattle(iOS)

It is possible to display a UIButton(iOS) in C++Builder.
developer.apple.com

sharedApplication()の中の、_di_NSArray __cdecl windows()

windows will have in the NSArray in sharedApplication.
When taking out a single object in this is UIWindow.

_di_UIWindow w1 = TUIWindow::Wrap(Fapp->windows()->lastObject() );

rootViewController exists in UIWindow.

rootViewController()->view()->addSubview(UIButton);

Make a class in which the UIButton is tapped.

Here it was programmed in Delphi.

It was not successful in C++Builder.

I've used this Delphi class. This is an example of UIButton.

#include <Macapi.ObjectiveC.hpp>
#include <Macapi.Helpers.hpp>
#include <Macapi.ObjCRuntime.hpp>

    FiOSUIButtonWrap = new TiOSUIButtonWrap(this, [=](){ Memo1->Lines->Append(L"UIButton Clickされた"); });
    FiOSUIButtonWrap->Button()->setTitle(StrToNSStr(L"日本語"),0 );
    FiOSUIButtonWrap->Button()->setBackgroundColor(AlphaColorToUIColor(TAlphaColorRec::Red));  //背景色
    FiOSUIButtonWrap->Button()->layer()->setCornerRadius(10);                                  //UIButtonの角の丸み
    FiOSUIButtonWrap->Button()->setFrame(CGRectMake(200,50,100,50));                           //位置と大きさ
    FiOSUIButtonWrap->Button()->setTitleColor(AlphaColorToUIColor(TAlphaColorRec::White), 0);  //文字色
    FiOSUIButtonWrap->Button()->setTitleColor(AlphaColorToUIColor(TAlphaColorRec::Blue), 1);   //タップ時文字色
    FiOSUIButtonWrap->Button()->layer()->setBorderWidth(1);                                    //ボタンの枠
    FiOSUIButtonWrap->Button()->layer()->setBorderColor(AlphaColorToUIColor(TAlphaColorRec::Blue)->CGColor()); //枠の色

    int iWin = Fapp->windows()->count() -1;

    _di_UIWindow w1 = TUIWindow::Wrap(Fapp->windows()->lastObject() );
    w1->rootViewController()->view()->addSubview(FiOSUIButtonWrap->Button());   //ボタンを配置する

UIButton setting.

name 機能
setTitle() 文字
setBackgroundColor() 背景色
layer()->setCornerRadius() 角丸み
setFrame() 位置と大きさ
setTitleColor() 文字の色
layer()->setBorderWidth() ボタンの枠
layer()->setBorderColor() 枠の色

Execution screen.

f:id:mojeld:20160120174844j:plain
Tap the "UIButton Create". UIButton will be created.
The red button is UIButton.
Tap the next red button.

[=](){ Memo1->Lines->Append(L"UIButton Clickされた"); }

It will be executed.