I've just upgraded my project from cocos2d 1.0.1 to 2.0 and after a lot of tweaking and all, I'm unable to change the default color of a CCLabelTTF like I did before (And this way I avoid one line of code for each label I create). Before, I was doing like that :
In CCLabelTTF.m :
- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment lineBreakMode:(CCLineBreakMode)lineBreakMode fontName:(NSString*)name fontSize:(CGFloat)size
{
if( (self=[super init]) ) {
dimensions_ = CGSizeMake( dimensions.width * CC_CONTENT_SCALE_FACTOR(), dimensions.height * CC_CONTENT_SCALE_FACTOR() );
alignment_ = alignment;
fontName_ = [name retain];
fontSize_ = size * CC_CONTENT_SCALE_FACTOR();
lineBreakMode_ = lineBreakMode;
color_ = ccBLACK;
[self setString:str];
}
return self;
}
I was changing the color inside this method since every "initWithString..." methods are returning this one, but even if I do so in cocos2D 2.0, it doesn't work.
Here's my new CCLabelTTF.m :
- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions hAlignment:(CCTextAlignment)alignment vAlignment:(CCVerticalTextAlignment) vertAlignment lineBreakMode:(CCLineBreakMode)lineBreakMode fontName:(NSString*)name fontSize:(CGFloat)size
{
if( (self=[super init]) ) {
// shader program
self.shaderProgram = [[CCShaderCache sharedShaderCache] programForKey:SHADER_PROGRAM];
dimensions_ = dimensions;
hAlignment_ = alignment;
vAlignment_ = vertAlignment;
fontName_ = [name retain];
fontSize_ = size;
lineBreakMode_ = lineBreakMode;
color_ = ccBLACK;
[self setString:str];
}
return self;
}
Is it because of the "ShaderProgram" thingy that wasn't there before 2.0? Please help I've tried everything so far :(
I even searched in all my project if there was a file containing "ccWHITE" or "{255,255,255}" but there's none related to CCLabelTTF (except for CCSprite, but if I change it to ccBLACK, all my sprites becomes black)
Instead of setting the ivar, use the accessor for the property:
self.color = ccBlack;
Also, you should not modify CCLabelTTF. If you want to change behaviour, make a subclass.
Related
I am learning about ObjectArx and as far as I know there are 3 common ways to create objects in Arx:
use acdbEntMake
use record.append (entity)
use a combination of record.append and transaction
so, my questions is:
can someone help me when I should use them in each case?
Do they have a big difference in performance with each other?
I am hesitant to use acdbentmake when the number of objects is large compared to the following two methods because I see very few examples that mention it.
I don't know what kind of entity You are creating but:
You don't need to use acdbEntMake in most cases. I'm using ObjectARX since about 8 years and never used it ;)
Transaction is used in .Net version of ObjectARX but You tagged visual-c++ so I suppose it's not this case.
If You warring about drawing large number of entities just test it. draw in the way You know and measure needed time. As long as You and Your clients accept drawing time, the way You are using is OK. In the future You always can refactor the code to get better performance if necessary.
To create for example line You may use this sample:
Acad::ErrorStatus AddLine(const AcGePoint3d SP , const AcGePoint3d EP , AcDbObjectId& id , AcDbObjectId Block )
{
AcDbLine* Line = new AcDbLine();
Line->setStartPoint(SP);
Line->setEndPoint(EP);
Acad::ErrorStatus es = Add( Line , Block );
if (es != Acad::eOk) { return es ;}
es = Line->close();
id = Line->objectId();
return es ;
}
Acad::ErrorStatus Add( AcDbEntity * pEnt, AcDbObjectId parent)
{
if ( !pEnt ) {
return Acad::eNullEntityPointer ;
}
Acad::ErrorStatus es;
if (parent.isNull()) {
parent = getActiveSpace()->objectId();
}
AcDbObject* pObj = NULL;
es = acdbOpenObject(pObj, parent , AcDb::kForWrite) ;
if (es != Acad::eOk) {
return es;
}
if (!pObj->isKindOf(AcDbBlockTableRecord::desc())) {
pObj->close();
return Acad::eWrongObjectType;
}
AcDbBlockTableRecord* Blok = AcDbBlockTableRecord::cast(pObj);
if ((es = Blok->appendAcDbEntity(pEnt)) != Acad::eOk )
{
Blok->close();
return es;
}
Blok->close();
return Acad::eOk;
}
AcDbBlockTableRecord* getActiveSpace()
{
AcDbBlockTableRecord* pOutVal = NULL;
AcDbDatabase * pDb = acdbHostApplicationServices()->workingDatabase();
if (!pDb) return NULL;
AcDbObjectId ActiveStpaceId = pDb->currentSpaceId();
AcDbObject* pObj = NULL;
Acad::ErrorStatus es;
es = acdbOpenObject(pObj, ActiveStpaceId , AcDb::kForRead);
if( es == Acad::eOk)
{
pOutVal = AcDbBlockTableRecord::cast(pObj);
es = pObj->close();
}
return pOutVal;
}
I've been experimenting all day and trying to figure out just how to get my UISearchBar to appear the same in iOS13 as it appears in iOS12/11
So the way the search bar is added is simply a new UISearchController.
var searchController = new UISearchController(searchResultsController: null);
searchController.SearchBar.Placeholder = "Search";
searchController.SearchResultsUpdater = this;
searchController.HidesNavigationBarDuringPresentation = false;
searchController.DimsBackgroundDuringPresentation = false;
NavigationItem.SearchController = searchController;
NavigationItem.HidesSearchBarWhenScrolling = false;
The results on iOS 11/12:
The results on iOS 13:
On iOS 13 I am using the new UINavigationBarAppearance code like this:
var appearance = new UINavigationBarAppearance();
appearance.ConfigureWithOpaqueBackground();
appearance.BackgroundColor = ColorPalette.TintColor;
appearance.TitleTextAttributes = new UIStringAttributes { ForegroundColor = UIColor.White };
NavigationItem.StandardAppearance = appearance;
On iOS 11/12 I am using legacy way to achieve it:
NavigationController.NavigationBar.BarStyle = UIBarStyle.Black;
NavigationController.NavigationBar.TintColor = UIColor.White;
NavigationController.NavigationBar.BarTintColor = ColorPalette.TintColor;
NavigationController.NavigationBar.Translucent = false;
I've tried a number of things, but can't seem to get the UISearchBar to tint by itself how iOS11/12 achieves it.
I know that the new UISearchBar now has access to the UITextField and I can configure the background color's etc.
searchBar.setSearchFieldBackgroundImage(UIImage(), for: .normal)
The code above has a side effect which removes corner radius of the text field.
Extension
extension UISearchBar {
/// This solves iOS 13 issue which is a light gray overay covers the textField.
/// - Parameter color: A color for searchField
func setSearchFieldBackgroundColor(_ color: UIColor) {
searchTextField.backgroundColor = color
setSearchFieldBackgroundImage(UIImage(), for: .normal)
// Make up the default cornerRadius changed by `setSearchFieldBackgroundImage(_:for:)`
searchTextField.layer.cornerRadius = 10
searchTextField.clipsToBounds = true
}
}
There were several properties added in iOS 13, so you need to use them with the help of a conditional. For changing the background color, you have to use the BackgroundColor property of the SearchBar, like this
searchController.SearchBar.BackgroundColor = UIColor.Red;
Use a custom renderer and override the OnElementChanged method this way
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
if (Control != null)
{
if(UIDevice.CurrentDevice.CheckSystemVersion(13,0))
Control.SearchTextField.BackgroundColor = Element.BackgroundColor.ToUIColor();
}
}
later on, you don't have to do anything else and worked for me on ios 12 and ios 13+
On iOS 13, you have access to the internal UISearchTextField through the SearchTextField property, you can set it's background directly (in my case, I need the background to be white). Be sure to check the iOS version to avoid exceptions.
if(UIDevice.CurrentDevice.CheckSystemVersion(13,0))
{
searchController.SearchBar.SearchTextField.BackgroundColor = UIColor.White;
}
You can achieve desired result by adding couple of lines.
searchBar.barTintColor = UIColor.red
searchBar.searchTextField.backgroundColor = UIColor.white
Before you try this code please link IB Outlets for searchBar
#IBOutlet weak var searchBar: UISearchBar!
I have the following in a Section:
_favElement = new StyledStringElement (string.Empty);
_favElement.Alignment = UITextAlignment.Center;
if (_room.IsFavourite) {
_favElement.Image = UIImage.FromBundle ("Images/thumbs_up.png");
_favElement.Caption = "Unmark as Favourite";
} else {
_favElement.Image = null;
_favElement.Caption = "Mark as Favourite";
}
_favElement.Tapped += favElement_Tapped;
Then when I press the element I want the following to happen:
private void favElement_Tapped ()
{
if (_room.IsFavourite) {
_favElement.Image = null;
_favElement.Caption = "Mark as Favourite";
} else {
_favElement.Image = UIImage.FromBundle ("Images/thumbs_up.png");
_favElement.Caption = "Unmark as Favourite";
}
_room.IsFavourite = !_room.IsFavourite;
}
However the image and text does not change in the actual element when the element is tapped. Is there a refresh method or something that must be called? I've also tried changing the Accessory on Tapped as well and nothing changes. The properties behind do reflect the correct values though.
An alternative to reloading the UITableView is to reload the Element using code like this (copied from Touch.Unit):
if (GetContainerTableView () != null) {
var root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);
}
assuming that your code is in DialogViewController,add this
this.ReloadData();
but in your case I recommend you to use BooleanImageElement
Does anyone has sample code for ordering in UITableView using NSOrderedSet?
Had read many articles about reordering, but still don't understand how to do this in iOS5.
Hi i implemented it like this. The "currentObject" is root object of the relationship and "subItems" the name of the ordered relationship in the model which is managed by the UITableViewController.
- (void)moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
NSMutableOrderedSet* orderedSet = [self.currentObject mutableOrderedSetValueForKey:#"subItems"];
NSInteger fromIndex = fromIndexPath.row;
NSInteger toIndex = toIndexPath.row;
// see http://www.wannabegeek.com/?p=74
NSIndexSet *indexes = [NSIndexSet indexSetWithIndex:fromIndex];
if (fromIndex > toIndex) {
// we're moving up
[orderedSet moveObjectsAtIndexes:indexes toIndex:toIndex];
} else {
// we're moving down
[orderedSet moveObjectsAtIndexes:indexes toIndex:toIndex-[indexes count]];
}
[self.dataStore saveObjectContext];
}
Setting the region in MKMapView occasionally results in the span being doubled. This bug seems to appear early in the map initialization phase. Although it's been reported elsewhere I wasn't able to find a descent existing workaround, so I'm posting my fix here. It relies on the fact that the regionThatFits method also produces the bug. I'm working with iPhone OS 3.12, but the bug was reported in 3.0 beta. This code lives in the UIViewController that contains your MKMapView:
- (BOOL)doubleSpanBugDetected:(MKCoordinateRegion)region fittedRegion:(MKCoordinateRegion)fitted
{
float latRatio = fitted.span.latitudeDelta / region.span.latitudeDelta;
float lonRatio = fitted.span.longitudeDelta / region.span.longitudeDelta;
BOOL latDoubled = (latRatio > 1.8 && latRatio < 2.2); // within 10% of x2
BOOL lonDoubled = (lonRatio > 1.8 && lonRatio < 2.2); // within 10% of x2
return latDoubled && lonDoubled;
}
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated
{
//fixes setRegion span doubling bug
// see: http://osmorphis.blogspot.com/2009/12/mapkit-span-doubling-bug.html
// see: http://www.iphonedevsdk.com/forum/iphone-sdk-development/15810-mkmapview-needs-time-think.html
MKCoordinateRegion fitted = [self.mapView regionThatFits:region];
if ([self doubleSpanBugDetected:region fittedRegion:fitted]) {
MKCoordinateSpan span = MKCoordinateSpanMake(fitted.span.latitudeDelta/2.0, fitted.span.longitudeDelta/2.0);
MKCoordinateRegion regionHack = MKCoordinateRegionMake(fitted.center, span);
[self.mapView setRegion:regionHack animated:animated];
} else {
[self.mapView setRegion:fitted animated:animated];
}
}