2016년 5월 20일 금요일
2016년 4월 14일 목요일
[android] 구글맵(Google Map) 레이아웃으로 구성된 커스텀 마커(이미지 + 텍스트) 생성하기
구글맵에서 제공하는 마커 기능을 사용해 레이아웃으로 구성된 상점 아이콘 이미지 + 상점명 텍스트를 오버레이 해본다.
- map_text_marker.xml
일단 map_text_marker.xml 라는 띄우고 싶은 마커모양을 디자인 한 xml파일을 만든다.
이런 모양의 마커를 출력하고 싶다. (ImageView + TextView)
- map_text_marker.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/iViewCategory" android:src="@drawable/ic_test" /> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:text="Store Name" android:id="@+id/tViewName" android:textColor="#000000" android:textSize="13dp" android:gravity="center_vertical" /> </LinearLayout>
위 xml을 불러와서 구현하기 위해 LayoutInflater 로 View를 생성하고, ImageView와 TextView를 view.findViewById(R.id.textView) 로 가져와서 원하는데로 수정해준다. 그 후 Google Map 객체의 addMarker 메서드를 이용해서 마커를 추가해주면 된다. 구현한 코드는 아래와 같다.
* facility.getName()은 상점 명이 들어있고, facility.getLatLng()는 위도 경도 LatLng가 들어있다.
* activity 는 Activity 객체
* facility.getName()은 상점 명이 들어있고, facility.getLatLng()는 위도 경도 LatLng가 들어있다.
* activity 는 Activity 객체
View marker = ((LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.map_text_marker, null);
TextView tViewName = (TextView) marker.findViewById(R.id.tViewName);
tViewName.setText(facility.getName());
Marker m = googleMap.addMarker(new MarkerOptions().visible(false).position(facility.getLatLng()).icon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(activity, marker))));
결과는 아래와 같이 표현된다.
위 스크린샷에서 위치 표시 ImageView의 아래 꼭지점 부분을 해당 좌표로 위치하게 하고 싶은데 마커의 기본적인 위치는 Marker의 Center Bottom으로 되어 있어서 위와 같이 제대로 된 위치에 찍히지 않게 되었다.
이를 해결하기 위해서 Anchor 기능을 이용할 예정이다.
2016년 4월 6일 수요일
[ios][objective-c] 접두사 NS가 붙는 이유 (prefix NS)
iOS 개발을 하다보면 클래스 이름에 NSString, NSSet과 같이 접두사(prefix) NS가 붙어있다.
애플 개발자 문서에 이렇게 설명되어 있다.
Historical Note: If you’re wondering why so many of the classes you encounter have an NS prefix, it’s because of the past history of Cocoa and Cocoa Touch. Cocoa began life as the collected frameworks used to build apps for the NeXTStep operating system. When Apple purchased NeXT back in 1996, much of NeXTStep was incorporated into OS X, including the existing class names. Cocoa Touch was introduced as the iOS equivalent of Cocoa; some classes are available in both Cocoa and Cocoa Touch, though there are also a large number of classes unique to each platform. Two-letter prefixes like NS and UI (for User Interface elements on iOS) are reserved for use by Apple.
애플사가 NextStep(NS)사를 인수했는데 이때 클래스 이름들이 중복되지 않아야 해서 NS라는 접두사를 붙였다고 한다.
Source: Programming with Objective-C
애플 개발자 문서에 이렇게 설명되어 있다.
Historical Note: If you’re wondering why so many of the classes you encounter have an NS prefix, it’s because of the past history of Cocoa and Cocoa Touch. Cocoa began life as the collected frameworks used to build apps for the NeXTStep operating system. When Apple purchased NeXT back in 1996, much of NeXTStep was incorporated into OS X, including the existing class names. Cocoa Touch was introduced as the iOS equivalent of Cocoa; some classes are available in both Cocoa and Cocoa Touch, though there are also a large number of classes unique to each platform. Two-letter prefixes like NS and UI (for User Interface elements on iOS) are reserved for use by Apple.
애플사가 NextStep(NS)사를 인수했는데 이때 클래스 이름들이 중복되지 않아야 해서 NS라는 접두사를 붙였다고 한다.
Source: Programming with Objective-C
2016년 4월 5일 화요일
[ios][swift] AppDelegate에서 UIAlertController 사용
func showAlertWithTitle(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler:
{ action in
switch action.style
{
case .Default:
print("default")
case .Cancel:
print("cancel")
case .Destructive:
print("destructive")
}
}))
dispatch_async(dispatch_get_main_queue(), {
self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)
})
}
showAlertWithTitle(title, message: message)로 호출하면 된다.
만약 코드 끝부분에 Alert 출력하는 부분에서 dispatch_async(dispatch_get_main_queue(), {} 로 감싸주지 않으면
Warning: Attempt to present <uialertcontroller: 0x125d424d0=""> on <reco_swift_sample .viewcontroller:="" 0x125e4aad0=""> whose view is not in the window hierarchy!
위와 같은 경고가 표시되면서 Alert이 뜨지 않는다.
피드 구독하기:
글 (Atom)

